最佳答案
你可以使用CABasicAnimation来绘制圆弧,例如
[无测试代码]
// e.g. 0.3 is 30%
func calculateEndAngle(percentageAsDouble: Double) -> CGFloat {
let endAngle:CGFloat = CGFloat(2 * M_PI - (M_PI * percentageAsDouble))
return endAngle
}
let animationCenter:CGPoint = self.view.center
let animationRadius:CGFloat = 100.0
let animationLineWidth:CGFloat = 16.0
let endAngle = calculateEndAngle(0.3)
let arcPath = UIBezierPath(arcCenter: animationCenter, radius: animationRadius, startAngle: CGFloat(M_PI), endAngle:endAngle, clockwise: true)
let arcLayer = CAShapeLayer()
arcLayer.path = arcPath.CGPath
arcLayer.fillColor = UIColor.clearColor().CGColor
arcLayer.strokeColor = UIColor.greenColor().CGColor
arcLayer.lineWidth = animationLineWidth
self.view.layer.addSublayer(arcLayer)
关于ios - 在 Swift 中绘制带标题的圆环图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37295147/