ios - 在 Swift 中绘制带标题的圆环图

标签 ios iphone swift charts draw

想知道如何用这样的标题绘制圆环图吗:

enter image description here

我尝试了几个库,但都没有成功。我无法在每个切片之间创建这些白线。带下划线的标题对我来说也太难了。任何帮助将不胜感激!提前致谢!

最佳答案

你可以使用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/

相关文章:

ios - 如何将此 OpenGL 指针数学转换为 Swift?

ios - Xamarin iOS 在应用程序从后台返回时呈现不同的 View Controller

ios - 知道来自 NSStream 的数据是完整的

ios - 在 iOS 中为 Storyboard 指定 App Delegate

iphone - 编辑 : UITextView Label is Cut in Half (Horizontally)

iphone - 10 分钟无交互后自动退出我的应用程序

ios - 自动布局不起作用?

ios - UITableViewCells中显示倒计时的方式,每个单元格倒计时应该有不同的时间

iphone 开发 : using tableview cells as a button

swift - 在 Swift 中创建一个带有泛型的函数,该函数返回另一个函数