绘制带有 Swift 标题的圆环图
Draw doughnut chart with titles in Swift
知道如何用这样的标题绘制圆环图吗:
我尝试了几个库,但都没有成功。我无法在每个切片之间创建这些白线。带下划线的标题对我来说也太难了。任何帮助将不胜感激!提前致谢!
可以使用CABasicAnimation画圆弧,例如
[none 测试代码]
// 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)
您可以使用以下库:
1.danielgindi/ios-charts library
知道如何用这样的标题绘制圆环图吗:
我尝试了几个库,但都没有成功。我无法在每个切片之间创建这些白线。带下划线的标题对我来说也太难了。任何帮助将不胜感激!提前致谢!
可以使用CABasicAnimation画圆弧,例如
[none 测试代码]
// 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)
您可以使用以下库:
1.danielgindi/ios-charts library