-
Notifications
You must be signed in to change notification settings - Fork 5
/
ActivityIndicator+UIView.swift
29 lines (24 loc) · 1.14 KB
/
ActivityIndicator+UIView.swift
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
extension UIView{
func activityStartAnimating(activityColor: UIColor, backgroundColor: UIColor) {
let backgroundView = UIView()
backgroundView.frame = CGRect.init(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)
backgroundView.backgroundColor = backgroundColor
backgroundView.tag = 475647
var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
activityIndicator = UIActivityIndicatorView(frame: CGRect.init(x: 0, y: 0, width: 50, height: 50))
activityIndicator.center = self.center
activityIndicator.hidesWhenStopped = true
activityIndicator.style = UIActivityIndicatorView.Style.gray
activityIndicator.color = activityColor
activityIndicator.startAnimating()
self.isUserInteractionEnabled = false
backgroundView.addSubview(activityIndicator)
self.addSubview(backgroundView)
}
func activityStopAnimating() {
if let background = viewWithTag(475647){
background.removeFromSuperview()
}
self.isUserInteractionEnabled = true
}
}