I am trying to create a progress bar that goes from 0%-100%. When the progress reaches 100%, I would like it to fade from the percentage to an image such as a check mark. I am setting this progress bar up as a CAShapeLayer and inside of it, I would like the the image to appear after it reaches 100. I see this animation done throughout various apps and I'm wondering if it is possible to do in Xcode. I have tried to do this by converting an image to a CAShapeLayer but it fails with a compiler error:
Cannot convert value of type 'UIImage?' to expected argument type 'String'
I have used the code below, but it only shows the percentage of loading. is it possible to be done?
private func beginDownloadingFile() {
print("Attempting to download file")
shapeLayer.strokeEnd = 0
let configuration = URLSessionConfiguration.default
let operationQueue = OperationQueue()
let urlSession = URLSession(configuration: configuration, delegate: self, delegateQueue: operationQueue)
guard let url = URL(string: urlString) else { return }
let downloadTask = urlSession.downloadTask(with: url)
downloadTask.resume()
}
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
let percentage = CGFloat(totalBytesWritten) / CGFloat(totalBytesExpectedToWrite)
DispatchQueue.main.async {
self.percentageLabel.text = "\(Int(percentage * 100))%"
self.shapeLayer.strokeEnd = percentage
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
}
print(percentage)
}
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
print("Finished downloading file")
}
Thank you for explaining whether or not this can be accomplished in advance.