-Display progress using UIProgressView -Notify processing completion using UIAlertController
PC | MacBook Air(13-inch,2017) |
PC OS | macOS Catalina(ver 10.15.6) |
IDE | Xcode(ver 12.0.1) |
iPhone | SE(2nd Generation) |
iPhone OS | ver 14.0.1 |
Swift | ver 5.3 |
-Create a project application called Sample
on the desktop using Xcode
-This time, write the code in ViewController.swift
in Sample
・ ʻUIProgressViewis placed on
Main.storyboard ・ ʻUIProgressView
has a constraint set to be placed in the center of the screen.
-The code example below is not refactored
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var progressView: UIProgressView!
override func viewDidLoad() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1){
self.progressView.setProgress(1/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 2){
self.progressView.setProgress(2/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 3){
self.progressView.setProgress(3/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 4){
self.progressView.setProgress(4/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 5){
self.progressView.setProgress(5/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 6){
self.progressView.setProgress(6/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 7){
self.progressView.setProgress(7/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 8){
self.progressView.setProgress(8/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 9){
self.progressView.setProgress(9/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 10){
self.progressView.setProgress(10/10, animated: true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 11){
let alert:UIAlertController = UIAlertController(title: "Notice", message: "Processing is finished", preferredStyle: .alert)
let action:UIAlertAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
}
override func viewWillAppear(_ animated: Bool) {
progressView.progress = 0
}
}
Recommended Posts