Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement