Home  >  Q&A  >  body text

ios - 如果对一个CALayer图层或者UIView视图中间镂空

一个背景黑色50%透明,中间镂空一个全透明的区域该怎么弄?

迷茫迷茫2721 days ago833

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:38:48

    When drawing View, use layer.mask to add a picture mask to the layer (you can make a gray and white picture, black is displayed, white is not displayed, and gray represents translucency).

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:38:48

    Wouldn’t it be nice to cover a fully transparent UIView with a translucent picture with a hollow in the middle

    reply
    0
  • 阿神

    阿神2017-04-17 13:38:48

    let path = UIBezierPath(rect:self.view.bounds)

        path.appendPath(UIBezierPath(rect: CGRect(x: 100, y: 100, width: 200, height: 300)).bezierPathByReversingPath())
        let shape = CAShapeLayer()
        
        shape.path = path.CGPath
        
        blurView.layer.mask = shape

    reply
    0
  • Cancelreply