fileprivate var containerView: UIView!
extension UIViewController {
func showLoadingView() {
containerView = UIView(frame: view.bounds)
view.addSubview(containerView)
containerView.backgroundColor = .systemBackground
containerView.alpha = 0
UIView.animate(withDuration: 0.25) {
containerView.alpha = 0.8
}
let activityIndicator = UIActivityIndicatorView(style: .large)
containerView.addSubview(activityIndicator)
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
activityIndicator.startAnimating()
}
func dismissLoadingView(){
DispatchQueue.main.async {
containerView.removeFromSuperview()
containerView = nil
}
}
}
'Programming > Swift' 카테고리의 다른 글
[Readable Coding Practice] eliminate empty UItableView cells (0) | 2021.06.28 |
---|---|
[Readable Code Practice] tableView Cell slide and delete (0) | 2021.06.28 |
[Readable Coding Practice] UIScrollView Pagination (0) | 2021.06.19 |
[Readable Coding Practice] Image Caching (0) | 2021.06.19 |
[Readable Coding Practice] Fetching data from REST API with URLSession (0) | 2021.06.18 |