Basically I am wanting to create a timer app. That's why I need a circle to show progress of timer. if timer is for 10 sec the circle will be divided into 10 segment and each segment will be appeared after one second. Ok fine.
I have successfully created it from SO post -> draw-a-circular-segment-progress-in-swift but a little bit problem. My circle's segment begins from fourth quadrent but it is not expected. I want to show the segment from first quadrent. Here I have created this function for 8 segments.
Please provide suggestion that can be used dynamically.
func createCircle(){
let circlePath = UIBezierPath(arcCenter: CGPoint(x: view.frame.size.width/2,y: view.frame.size.height/2), radius: CGFloat(90), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let segmentAngle: CGFloat = (360 * 0.125) / 360
for i in 0 ..< 8 {
let circleLayer = CAShapeLayer()
circleLayer.path = circlePath.CGPath
// start angle is number of segments * the segment angle
circleLayer.strokeStart = segmentAngle * CGFloat(i) //I think all is for this line of code.
print("\nStroke \(i): ",segmentAngle * CGFloat(i))
// end angle is the start plus one segment, minus a little to make a gap
// you'll have to play with this value to get it to look right at the size you need
let gapSize: CGFloat = 0.008
circleLayer.strokeEnd = circleLayer.strokeStart + segmentAngle - gapSize
circleLayer.lineWidth = 10
circleLayer.strokeColor = UIColor(red:0, green:0.004, blue:0.549, alpha:1).CGColor
circleLayer.fillColor = UIColor.clearColor().CGColor
// add the segment to the segments array and to the view
segments.insert(circleLayer, atIndex: i)
}
for i in 0 ..< 8{
view.layer.addSublayer(segments[i])
}
}