CALayer:创建带有圆边的破碎椭圆?
CALayer: create broken ellipse with round edges?
这是我将椭圆 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)
我得到的结果:
但是,我想得到这个结果:
你能帮我拿这个吗?
感谢您的帮助!
要让你的线帽变圆,只需告诉你的形状层使用圆形线帽:
circleLayer.lineCap = .round
这是我将椭圆 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)
我得到的结果:
但是,我想得到这个结果:
你能帮我拿这个吗?
感谢您的帮助!
要让你的线帽变圆,只需告诉你的形状层使用圆形线帽:
circleLayer.lineCap = .round