CALayer:创建带有圆边的破碎椭圆?

问题描述

这是我向 CALayer 添加椭圆 UIView代码

let circleLayer = CAShapeLayer()
circleLayer.path = UIBezierPath(arcCenter: CGPoint(x: frame.size.width / 2,y: frame.size.height / 2),radius: frame.size.width / 2,startAngle: -.pi / 2,endAngle: .pi / 6,clockwise: false).cgPath
circleLayer.linewidth = 8.0
circleLayer.cornerRadius = 4.0
circleLayer.strokeColor = UIColor.black.cgColor
circleLayer.fillColor = UIColor.clear.cgColor
circleLayer.lineJoin = .round
squareView.layer.backgroundColor = UIColor.clear.cgColor
squareView.layer.addSublayer(circleLayer)

我得到的结果:

enter image description here

但是,我想得到这个结果:

enter image description here

你能帮我得到这个吗?

感谢您的帮助!

解决方法

要使您的线帽变圆,只需告诉您的形状图层使用圆形线帽:

circleLayer.lineCap = .round