- declare
This file contains 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 | |
class ProgressDialogView: UIView { | |
let activityIndictor: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.white) | |
init() { | |
super.init(frame: CGRect(x: 0, | |
y: 0, | |
width: 0, | |
height: 0)) | |
self.setup() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
self.setup() | |
} | |
func setup() { | |
self.addSubview(activityIndictor) | |
activityIndictor.startAnimating() | |
} | |
override func didMoveToSuperview() { | |
super.didMoveToSuperview() | |
if let superview = self.superview { | |
let width = superview.frame.size.width | |
let height = superview.frame.size.height | |
self.frame = CGRect(x: 0, | |
y: 0, | |
width: width, | |
height: height) | |
self.backgroundColor = UIColor.init(white: 0.0, alpha: 0.5) | |
let activityIndicatorSize: CGFloat = 40 | |
activityIndictor.frame = CGRect(x: width / 2 - activityIndicatorSize / 2, | |
y: height / 2 - activityIndicatorSize / 2, | |
width: activityIndicatorSize, | |
height: activityIndicatorSize) | |
layer.masksToBounds = true | |
} | |
} | |
func show() { | |
self.isHidden = false | |
} | |
func hide() { | |
self.isHidden = true | |
} | |
} |
- usage
This file contains 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 | |
class UsageUIViewController: UIViewController { | |
let progressDialog:ProgressDialogView = ProgressDialogView() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.addSubview(progressDialog) | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
showProgressDialog() | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
hideProgressDialog() | |
} | |
func showProgressDialog() { | |
self.progressDialog.show() | |
} | |
func hideProgressDialog() { | |
self.progressDialog.hide() | |
} | |
} |
- preview
'iOS' 카테고리의 다른 글
[swift3] custom segue transition animation (0) | 2019.02.27 |
---|---|
[iOS] how to create iOS/swift .gitignore in MacOS terminal(console) (0) | 2019.02.18 |
[swift3] Handler Example (0) | 2017.06.21 |
[swift3] convert Dictionary to Data, Data to String in swift3 (0) | 2017.05.29 |
[iOS]Pods framework not found ... error (0) | 2017.05.22 |