Created
January 16, 2019 10:25
-
-
Save shishirthedev/06d272fef7981a674532a400fdb071fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| public class ActivityIndicator { | |
| private init(){} | |
| public static let shared = ActivityIndicator() | |
| var activityLabel: UILabel! | |
| var activityIndicator:UIActivityIndicatorView! | |
| var activityView: UIVisualEffectView! | |
| func startAnimating(with title: String, in vc: UIViewController){ | |
| // Acitivty Label.............. | |
| activityLabel = UILabel(frame: CGRect(x: 50, | |
| y: 0, | |
| width: 200, | |
| height: 50)) | |
| activityLabel.text = title | |
| activityLabel.textColor = UIColor.black | |
| activityLabel.alpha = 0.8 | |
| // Activity Indicator................. | |
| activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) | |
| activityIndicator.frame = CGRect(x: 0, | |
| y: 0, | |
| width: 50, | |
| height: 50) | |
| activityIndicator.startAnimating() | |
| // Activity View.................... | |
| if #available(iOS 10.0, *) { | |
| let effect = UIBlurEffect(style: .prominent) | |
| activityView = UIVisualEffectView(effect: effect) | |
| } else { | |
| activityView = UIVisualEffectView() | |
| activityView.backgroundColor = UIColor.darkGray | |
| // Fallback on earlier versions | |
| } | |
| activityView.frame = CGRect(x: vc.view.frame.midX - activityLabel.frame.width/2, | |
| y: vc.view.frame.midY - activityLabel.frame.height/2, | |
| width: 200, | |
| height: 50) | |
| activityView.layer.cornerRadius = 10 | |
| activityView.layer.masksToBounds = true | |
| // Attaching View................... | |
| activityView.contentView.addSubview(activityIndicator) | |
| activityView.contentView.addSubview(activityLabel) | |
| vc.view.addSubview(activityView) | |
| } | |
| func stopAnimating(){ | |
| activityView.removeFromSuperview() | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment