带阴影的线圆

Line circle with shadow

我正在尝试绘制一个带有阴影的描边颜色的空圆。

let bezierPath              = UIBezierPath(ovalIn: CGRect(x: 80, y: 200, width: 100, height: 100))

let shapeLayer              = CAShapeLayer()
shapeLayer.path             = bezierPath.cgPath
shapeLayer.fillColor        = UIColor.clear.cgColor
shapeLayer.strokeColor      = UIColor.white.cgColor
shapeLayer.lineWidth        = 3
shapeLayer.shadowPath       = bezierPath.cgPath
shapeLayer.shadowColor      = UIColor.black.cgColor
shapeLayer.shadowOffset     = CGSize(width: 0, height: 0)
shapeLayer.shadowOpacity    = 1

containerView.layer.addSublayer(shapeLayer)

但是阴影充满了整个圆圈。如何去除它并保留外部阴影?

只要省略设置shapeLayer.shadowPath,你会得到这样的东西(图层的标准阴影,基本上是图层的不透明部分):