self.showSpinner(onView: self.view,title : "取得資料中,請稍候!")
let seconds = 1.0
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
// Put your code which should be executed with a delay here
self.removeSpinner()
}
///等待的畫面,參考資料 http://brainwashinc.com/2017/07/21/loading-activity-indicator-ios-swift/
var vSpinner : UIView?
extension UIViewController {
func showSpinner(onView : UIView,title:String) {
let spinnerView = UIView.init(frame: onView.bounds)
spinnerView.backgroundColor = UIColor.init(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)
let ai = UIActivityIndicatorView.init(style: .whiteLarge)
ai.startAnimating()
ai.center = spinnerView.center
DispatchQueue.main.async {
spinnerView.addSubview(ai)
onView.addSubview(spinnerView)
}
vSpinner = spinnerView
}
func removeSpinner() {
DispatchQueue.main.async {
vSpinner?.removeFromSuperview()
vSpinner = nil
}
}
}
沒有留言:
張貼留言