Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.78 KB | None | 0 0
  1. import Foundation
  2.  
  3. import UIKit
  4. import SnapKit
  5.  
  6. protocol Spinnable where Self: UIViewController {
  7.     func showActivityIndicator()
  8.     func hideActivityIndicator()
  9. }
  10.  
  11. extension Spinnable {
  12.     func showActivityIndicator() {
  13.         let activityIndicator = UIActivityIndicatorView()
  14.         self.view.addSubview(activityIndicator)
  15.         activityIndicator.snp.makeConstraints { (make) in
  16.             make.centerX.centerY.equalToSuperview()
  17.             make.width.height.equalTo(50)
  18.         }
  19.     }
  20.    
  21.     func hideActivityIndicator() {
  22.         for view in self.view.subviews {
  23.             guard let activityIndicator = view as? UIActivityIndicatorView else {
  24.                 continue
  25.             }
  26.             activityIndicator.removeFromSuperview()
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement