[Swift] Use UIProgressView to display progress + UIAlertController to notify processing completion

to write

-Display progress using UIProgressView -Notify processing completion using UIAlertController

Image of processing

Development environment

PCMacBook Air(13-inch,2017)
PC OSmacOS Catalina(ver 10.15.6)
IDEXcode(ver 12.0.1)
iPhoneSE(2nd Generation)
iPhone OSver 14.0.1
Swiftver 5.3

Prerequisites

-Create a project application called Sample on the desktop using Xcode -This time, write the code in ViewController.swift in Sample ・ ʻUIProgressViewis placed onMain.storyboard ・ ʻUIProgressView has a constraint set to be placed in the center of the screen. -The code example below is not refactored

Code example

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

[Swift] Use UIProgressView to display progress + UIAlertController to notify processing completion
[Swift] How to use UserDefaults
How to use Swift UIScrollView
[Swift] Processing to share screenshots
[Swift] Another way to use Result?
[Processing × Java] How to use variables
[Swift] How to use SwiftLint (cocoapods)
[Swift] How to use Unwind segue
[Processing × Java] How to use arrays
Use SQL statements to display specific records
[Swift] How to use Tab Bar Controller
[Processing × Java] How to use the loop
[Processing × Java] How to use the class
[Rails] How to use video_tag to display videos
[Swift] How to use one option alert