-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIJProgressView.swift
61 lines (48 loc) · 1.88 KB
/
IJProgressView.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// IJProgressView.swift
// IJProgressView
//
// Created by Isuru Nanayakkara on 1/14/15.
// Copyright (c) 2015 Appex. All rights reserved.
//
import UIKit
open class IJProgressView {
var containerView = UIView()
var progressView = UIView()
var activityIndicator = UIActivityIndicatorView()
open class var shared: IJProgressView {
struct Static {
static let instance: IJProgressView = IJProgressView()
}
return Static.instance
}
open func showProgressView(_ view: UIView) {
containerView.frame = view.frame
containerView.center = view.center
containerView.backgroundColor = UIColor(hex: 0xffffff, alpha: 0.3)
progressView.frame = CGRect(x: 0, y: 0, width: 80, height: 80)
progressView.center = view.center
progressView.backgroundColor = UIColor(hex: 0x444444, alpha: 0.7)
progressView.clipsToBounds = true
progressView.layer.cornerRadius = 10
activityIndicator.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
activityIndicator.activityIndicatorViewStyle = .whiteLarge
activityIndicator.center = CGPoint(x: progressView.bounds.width / 2, y: progressView.bounds.height / 2)
progressView.addSubview(activityIndicator)
containerView.addSubview(progressView)
view.addSubview(containerView)
activityIndicator.startAnimating()
}
open func hideProgressView() {
activityIndicator.stopAnimating()
containerView.removeFromSuperview()
}
}
extension UIColor {
convenience init(hex: UInt32, alpha: CGFloat) {
let red = CGFloat((hex & 0xFF0000) >> 16)/256.0
let green = CGFloat((hex & 0xFF00) >> 8)/256.0
let blue = CGFloat(hex & 0xFF)/256.0
self.init(red: red, green: green, blue: blue, alpha: alpha)
}
}