我创建了带有阴影的直线圆,但是当我尝试更改shadowRadius
时,阴影没有显示
let path = UIBezierPath(ovalIn: rect)
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.white.cgColor
shapeLayer.lineWidth = 1
shapeLayer.shadowOpacity = 0.9
shapeLayer.shadowColor = UIColor.white.cgColor
shapeLayer.shadowOffset = .zero
shapeLayer.shadowRadius = 10.0
//shapeLayer.shadowPath = path.cgPath
layer.addSublayer(shapeLayer)
line circle with default corner radius
line circle with corner radius 10.0
有人可以帮助我吗?
答案 0 :(得分:1)
如果要在“更强”的阴影上创建效果,可以通过使用阴影路径将其描画得比“投射阴影”的路径大来实现。可以使用copy(strokingWithWidth:lineCap:lineJoin:miterLimit:transform:)
:
shapeLayer.shadowPath = path.cgPath.copy(strokingWithWidth: width, lineCap: .round, lineJoin: .round, miterLimit: 0)
这是这样的阴影(红色),无论有无模糊(阴影半径):
您可以配置描边阴影路径的shadowBlur
和width
以达到所追求的效果。下面是一些示例: