我可以创建一个圆圈,但我需要它从“12:00”开始并达到一定的百分比。
let circlePath = UIBezierPath(arcCenter: CGPoint(x: 100,y: 100), radius: CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.CGPath
//change the fill color
shapeLayer.fillColor = UIColor.clearColor().CGColor
//you can change the stroke color
shapeLayer.strokeColor = UIColor.redColor().CGColor
//you can change the line width
shapeLayer.lineWidth = 3.0
cell.progress.layer.addSublayer(shapeLayer)
答案 0 :(得分:4)
您需要调整开始和结束角度以符合您的标准。
" 12:00"在圆圈上将是3pi / 2或-pi / 2(-M_PI_2
)。整圆是2pi(M_PI * 2
)。其中一定百分比当然是M_PI * 2 * percentage
。所以结束将是你的开始+那个百分比。
let circlePath = UIBezierPath(arcCenter: CGPoint(x: 100,y: 100), radius: CGFloat(20), startAngle: CGFloat(-M_PI_2), endAngle:CGFloat(M_PI * 2 * percentage - M_PI_2), clockwise: true)
其中percentage
在CGFloat
到0.0
范围内的某些1.0
。