0
votes

I want to create one rectangle layer of progress bar around my object it maybe anything it should be an uibutton, uiview or any object so i create a below code:

let layer_ca = CAShapeLayer.init()
    layer_ca.strokeColor = UIColor.green.cgColor
    layer_ca.lineWidth  = 10.0
    layer_ca.fillColor = UIColor.clear.cgColor

    let bezier_path = UIBezierPath.init(roundedRect: CGRect.init(x: captureButton.frame.origin.x, y: captureButton.frame.origin.y, width: captureButton.frame.width, height: captureButton.frame.height), cornerRadius: 15)

        bezier_path.move(to: CGPoint(x: 12, y: 15))

    layer_ca.path = bezier_path.cgPath

    let animation = CABasicAnimation.init(keyPath: "strokeEnd")
    animation.fromValue = NSNumber.init(value: 0.0)
    animation.toValue = NSNumber.init(value: 1.0)
    animation.duration = 2.0

    layer_ca.add(animation, forKey: "myStroke")

    self.view.layer.addSublayer(layer_ca)

here "captureButton" was an my object so its created successful above the object with the cabasicanimation and now what my question was how to change the ending point of the path and how should i stop the path to half of the distance path and then i continue with the same path which i stop previous path whenever i call to start.

i need exactly like as a rectangular progress bar around an object.

please help me anyone who should known the answer..!

1

1 Answers

0
votes

I just have the same question, and spend a few hours to figure it out. if you want control the start point or end point, you should create your own BezierPath, and custom your path. bezierPath.move("start position"), and there it is, the last point will be the end position.