Skip to content

Instantly share code, notes, and snippets.

@marcos1262
Last active October 27, 2018 14:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save marcos1262/8028e1b4a7eb56339a26ce5121d98fbc to your computer and use it in GitHub Desktop.
Spinner indicator to put over loading views
extension UIViewController {
func displaySpinner(onView : UIView) -> UIView {
let spinnerView = UIView.init(frame: onView.bounds)
spinnerView.backgroundColor = UIColor.white //UIColor.black.withAlphaComponent(0.5)
let ai = UIActivityIndicatorView(style: .gray)
ai.startAnimating()
ai.center = spinnerView.center
DispatchQueue.main.async {
spinnerView.addSubview(ai)
onView.addSubview(spinnerView)
}
return spinnerView
}
func removeSpinner(spinner :UIView) {
DispatchQueue.main.async {
spinner.removeFromSuperview()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment