iOS Add loader
add loader in ios
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
//create an extension for UIViewController which //contains getActivityIndicator method extension UIViewController { func getActivityIndicator(_ title: String) -> UIView { var activityIndicator = UIActivityIndicatorView() var strLabel = UILabel() let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark)) let mainUi = UIView() strLabel.removeFromSuperview() activityIndicator.removeFromSuperview() effectView.removeFromSuperview() strLabel = UILabel(frame: CGRect(x: 50, y: 0, width: 160, height: 46)) strLabel.text = title strLabel.font = .systemFont(ofSize: 14, weight: .medium) strLabel.textColor = UIColor(white: 0.9, alpha: 0.7) effectView.frame = CGRect(x: view.frame.midX - 80, y: view.frame.midY - strLabel.frame.height/2 , width: 160, height: 46) effectView.layer.cornerRadius = 3 effectView.layer.masksToBounds = true activityIndicator = UIActivityIndicatorView(style: .white) activityIndicator.frame = CGRect(x: 0, y: 0, width: 46, height: 46) activityIndicator.startAnimating() effectView.contentView.addSubview(activityIndicator) effectView.contentView.addSubview(strLabel) mainUi.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height) mainUi.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.4) mainUi.addSubview(effectView) return mainUi } } // then in your viewcontroler create a field fileprivate var viewloader:UIView? //initlize view viewloader = getActivityIndicator("Loading...") // add view when you need view.addSubview(viewloader!) //remove view when you don't need self.viewloader?.removeFromSuperview() |