Last active
March 20, 2021 12:22
-
-
Save amfathi/c3477239095dac1bb3c63cf64efe476d to your computer and use it in GitHub Desktop.
Convenient ProgressView in UIAlertController to block the UI till completion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ProgressView { | |
private lazy var progressView: UIProgressView = { | |
let progressView = UIProgressView(frame: CGRect(x: 15, y: 20, width: 240, height: 8)) | |
return progressView | |
}() | |
private lazy var alert: UIAlertController = { | |
let alert = UIAlertController(title: "", message: "", preferredStyle: .alert) | |
alert.view.addSubview(progressView) | |
return alert | |
}() | |
private weak var presentingViewController: UIViewController? | |
init(presentingViewController: UIViewController) { | |
self.presentingViewController = presentingViewController | |
} | |
func present() { | |
progressView.progress = 0 | |
presentingViewController?.present(alert, animated: true) | |
} | |
func setProgress(_ progress: Float) { | |
progressView.progress = progress | |
} | |
func dismiss(completion: (() -> Void)? = nil) { | |
alert.dismiss(animated: true, completion: completion) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment