I have created some code whereby I animate my custom progressbar.Below is the code I have so far which handles the animation and label.
let animationProgress= CABasicAnimation(keyPath: "strokeEnd")
let value = 0.8
animationProgress.fromValue = 0
animationProgress.toValue = value (will display 80% of the progressbar)
animationProgress.duration = 1
while value <= 1 {
DispatchQueue.main.async {
updateYourUI()
}
}
animationProgress.isRemovedOnCompletion = false
animationProgress.fillMode = kCAFillModeForwards
shapeLayer.add(animationProgress, forKey: "animated")
func updateYourUI (){
let value= 50
view.PercentageComplete.text = "\((value))%"
view.shapeLayer.strokeEnd = CGFloat(value)
}
How can I get the "let value" display each value from "fromValue" and "toValue " so that they label will display the corresponding value as the progressbar animation is run. I have tried to implement a while loop howerver I am unsure of what condition to place so that it runs for every value from the "animationProgress.fromValue = 0" to the "animationProgress.toValue".