我想在 UIView 和 Swift3、iOS 的阴影层中“切一个洞”
我有一个容器 (UIView),它有 2 个孩子:
我想给叠加一个阴影并切出该阴影的内部矩形,以在 ImageView 的边缘创建类似发光的效果
插入发光至关重要,因为图像占用了屏幕宽度
我的代码迄今为止:
let glowView = UIView(frame: CGRect(x: 0, y: 0, width: imageWidth, height: imageHeight))
glowView.layer.shadowPath = UIBezierPath(roundedRect: container.bounds, cornerRadius: 4.0).cgPath
glowView.layer.shouldRasterize = true
glowView.layer.rasterizationScale = UIScreen.main.scale
glowView.layer.shadowOffset = CGSize(width: 1.0, height: 1.0)
glowView.layer.shadowOpacity = 0.4
container.addSubview(imageView)
container.addSubview(glowView)
Run Code Online (Sandbox Code Playgroud)
结果如下所示:
现在我想剪掉较暗的内部部分,以便只保留边缘的阴影
任何想法如何实现?