Progress View
The ProgressView is used in iOS applications to show the task's progress over time. The ProgressView is a UIProgressView instance that inherits the UIView class.
class UIProgressView : UIView
The ProgressView displays the progress bar, which we can customise using the UIProgressView class's methods and attributes. We can retrieve and change the values that are tied to a task's progress.
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var nameTF: UITextField!
@IBOutlet weak var emailTF: UITextField!
@IBOutlet weak var passwordTF: UITextField!
@IBOutlet weak var CFPasswordTF: UITextField!
@IBOutlet weak var progressView: UIProgressView!
@IBOutlet weak var msgLbl: UILabel!
@IBOutlet weak var sbmtBtn: UIButton!
let progress = Progress(totalUnitCount: 4)
var ratio: Float?
override func viewDidLoad() {
super.viewDidLoad()
After loading the view, do any extra configuration.
progressView.isHidden = true
ratio = 0
progressView.progress = ratio!
msgLbl.isHidden = true
progressView.layer.cornerRadius = 10
sbmtBtn.layer.cornerRadius = 10
}
@IBAction func clickedSubmitBtn(_ sender: Any) {
if(nameTF.text != "" && emailTF.text != "" && passwordTF.text != ""){
sbmtBtn.isHidden = true
msgLbl.isHidden = false
progressView.isHidden = false
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { (timer) in
guard self.progress.isFinished == false else{
timer.invalidate()
self.msgLbl.text = "Data Saved"
return
}
self.progress.completedUnitCount += 1
let progrsssFloat = Float(self.progress.fractionCompleted)
self.progressView.setProgress(progrsssFloat, animated: true)
}
}
}
}