我有教程的自定义视图。 大厅的屏幕是黑色的,在展示套房视图中有一个“洞”。 我想在“洞”周围添加一个阴影
我试过这个:
backgroundColor = UIColor.blackColor()
alpha = 0.5
// Create the shape to mask
let path = createPathOfShape(shape)
//this masking works - adding the "hole"
let maskLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.fillColor = UIColor.blackColor().CGColor
maskLayer.fillRule = kCAFillRuleEvenOdd
maskLayer.path = path.CGPath
layer.mask = maskLayer
//this is not working - adding the shadow to the "hole"
let glow = CAShapeLayer()
glow.frame = bounds
glow.fillColor = UIColor.redColor().CGColor
glow.path = path.CGPath
glow.shadowColor = UIColor.blackColor().CGColor
glow.shadowRadius = 10
glow.shadowOffset = CGSizeZero
glow.shadowOpacity = 0.5
layer.addSublayer(glow)
有什么建议吗? 感谢