Last active
June 22, 2021 15:10
-
-
Save sukov/b4949987bfe96754575265c740aea32f to your computer and use it in GitHub Desktop.
Revisions
-
sukov revised this gist
Jun 22, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ extension UIButton { /// Unique number used to tag the loading indicator view private var loadingIndicatorTag: Int { 808404 @@ -26,4 +27,5 @@ alpha = 1.0 loadingIndicator?.stopAnimating() loadingIndicator?.removeFromSuperview() } } -
sukov revised this gist
Jun 22, 2021 . 1 changed file with 28 additions and 23 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,29 @@ /// Unique number used to tag the loading indicator view private var loadingIndicatorTag: Int { 808404 } private var loadingIndicator: UIActivityIndicatorView? { viewWithTag(loadingIndicatorTag) as? UIActivityIndicatorView } func displayLoadingIndicator() { isEnabled = false alpha = 0.8 let indicator = UIActivityIndicatorView(style: .medium) indicator.color = .white let buttonHeight = self.bounds.size.height let buttonWidth = self.bounds.size.width let titleLabelMaxX = titleLabel?.frame.maxX ?? 0 indicator.center = CGPoint(x: titleLabelMaxX + (buttonWidth - titleLabelMaxX) / 2, y: buttonHeight / 2) indicator.tag = loadingIndicatorTag addSubview(indicator) indicator.startAnimating() } func hideLoadingIndicator() { isEnabled = true alpha = 1.0 loadingIndicator?.stopAnimating() loadingIndicator?.removeFromSuperview() } -
sukov created this gist
Jun 30, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ extension UIButton { func loadingIndicator(_ show: Bool) { let tag = 808404 if show { self.isEnabled = false self.alpha = 0.8 let indicator = UIActivityIndicatorView() let buttonHeight = self.bounds.size.height let buttonWidth = self.bounds.size.width let titleLabelMaxX = titleLabel?.frame.maxX ?? 0 indicator.center = CGPoint(x: titleLabelMaxX + (buttonWidth - titleLabelMaxX) / 2, y: buttonHeight / 2) indicator.tag = tag self.addSubview(indicator) indicator.startAnimating() } else { self.isEnabled = true self.alpha = 1.0 if let indicator = self.viewWithTag(tag) as? UIActivityIndicatorView { indicator.stopAnimating() indicator.removeFromSuperview() } } } }