Swift 部分圆弧的内阴影

Inner shadow for partial arc with Swift

我想为圆弧创建一个内部阴影,但我得到的是半个圆而不是阴影(见下图)。

我的代码是:

let rect = self.bounds
let segmentArcPath = UIBezierPath()
segmentArcPath.addArc(withCenter: rect.center,
                      radius: (rect.height - insetShadow) / 2,
                      startAngle: -.pi/2,
                      endAngle: value * 2 * .pi - .pi/2,
                      clockwise: true)

shadowPath = segmentArcPath.cgPath

已经尝试添加两条路径(不关闭阴影),但没有成功:

let rect = self.bounds
let segmentArcPath = UIBezierPath()
segmentArcPath.addArc(withCenter: rect.center,
                      radius: (rect.height - insetShadow) / 2,
                      startAngle: internalStrokeStart,
                      endAngle: internalStrokeEnd,
                      clockwise: true)

let segmentArcPath2 = UIBezierPath()
segmentArcPath2.addArc(withCenter: rect.center,
                      radius: (rect.height - insetShadow) / 2 - 5,
                      startAngle: internalStrokeStart,
                      endAngle: internalStrokeEnd,
                      clockwise: false)

segmentArcPath.append(segmentArcPath2)
shadowPath = segmentArcPath.cgPath

如何创建如上图所示的阴影?你有什么提示吗?

根据@vacawama 的推荐:

Only create one UIBezierPath. After drawng the outer arc, draw a 5 unit line towards the center of the arc, then call addArc to add the inner arc to the same path

let rect = self.bounds
let outerRadius = (rect.height - insetShadow) / 2
let segmentArcPath = UIBezierPath()
segmentArcPath.addArc(withCenter: rect.center,
                      radius: outerRadius,
                      startAngle: internalStrokeStart,
                      endAngle: internalStrokeEnd,
                      clockwise: true)
let innerCircleRadius = outerRadius - 2
let startPointXInnerCircle = cos(internalStrokeEnd) * innerCircleRadius + rect.center.x
let startPointYInnerCircle = sin(internalStrokeEnd) * innerCircleRadius + rect.center.y

segmentArcPath.addLine(to: CGPoint(x: startPointXInnerCircle, y: startPointYInnerCircle))

segmentArcPath.addArc(withCenter: rect.center,
                      radius: innerCircleRadius,
                      startAngle: internalStrokeEnd,
                      endAngle: internalStrokeStart,
                      clockwise: false)

shadowPath = segmentArcPath.cgPath