swift - 带有阴影和屏蔽层的ios UIView

  显示原文与译文双语对照的内容
80 3

所以我有一个 UIView ( 叫做 myView ),上面有一些面具。

let maskPath = UIBezierPath(roundedRect: myView.bounds, byRoundingCorners: [.topLeft,. topRight], cornerRadii: CGSize(width: 12, height: 12))
let maskLayer = CAShapeLayer()
maskLayer.frame = myView.bounds
maskLayer.path = maskPath.cgPath
myView.layer.mask = maskLayer

这种布局的布局:

enter image description here

我没有做的是添加一些阴影 myView因为视图层有一个掩码,所以我无法将它的他层添加到阴影中。

有谁遇到过这个问题?

时间:原作者:0个回答

82 5

将图像颜色设置为清晰,并进行以下操作:

let maskPath = UIBezierPath(roundedRect: redView.bounds, byRoundingCorners: [.topLeft,. topRight], cornerRadii: CGSize(width: 12, height: 12))
 let maskLayer = CAShapeLayer()[![enter image description here][1]][1]
 maskLayer.fillColor = UIColor.red.cgColor//your color
 maskLayer.frame = redView.bounds
 maskLayer.path = maskPath.cgPath
 redView.layer.addSublayer(maskLayer)
 redView.layer.shadowOffset = CGSize(width: 10, height: 10)
 redView.layer.shadowColor = UIColor.green.cgColor
 redView.layer.shadowOpacity = 1
原作者:
...