SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extension UIViewController {
  2.     private static let association = ObjectAssociation<UIActivityIndicatorView>()
  3.    
  4.     var thisActivityIndicator: UIActivityIndicatorView {
  5.         set { UIViewController.association[self] = newValue }
  6.         get {
  7.             if let indicator = UIViewController.association[self] {
  8.                 return indicator
  9.             } else {
  10.                 UIViewController.association[self] = UIActivityIndicatorView.customIndicator(at: self.view.center)
  11.                 return UIViewController.association[self]!
  12.             }
  13.         }
  14.     }
  15.    
  16.     // MARK: - Acitivity Indicator
  17.    
  18.     public func startIndicatingActivity() {
  19.         DispatchQueue.main.async {
  20.             self.view.addSubview(self.thisActivityIndicator)
  21.             self.thisActivityIndicator.startAnimating()
  22.         }
  23.     }
  24.    
  25.     public func stopIndicatingActivity() {
  26.         DispatchQueue.main.async {
  27.             self.thisActivityIndicator.removeFromSuperview()
  28.             self.thisActivityIndicator.stopAnimating()
  29.         }
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top