This simple extension adds progress indicator to rounded UIButton.
Just add file ExtButtonProgress.swift in your project. Use method showProgressIndicator( width:color:backgroundColor:cycleDuration:) to begin show progress indicator and method hideProgressIndicator() to hide indicator.
Important! Button must be rounded for using this extension.
Code example
class ViewController: UIViewController {
// Our rounded button
@IBOutlet weak var roundedButton: UIButton!
// Push 'Start' button
@IBAction func pushStart(_ sender: UIButton) {
// Show progress indicator for our buttnon
roundedButton.showProgressIndicator(width: 5, color: UIColor.purple, backgroundColor: UIColor.lightGray, cycleDuration: 7.0)
}
// Push 'Stop' button
@IBAction func pushStop(_ sender: UIButton) {
// Hide progress indicator
roundedButton.hideProgressIndicator()
}
override func viewDidLoad() {
super.viewDidLoad()
// Make rounded button
roundedButton.layer.cornerRadius = 0.5 * buttonWithProgressbar.bounds.size.width
roundedButton.clipsToBounds = true
}
}
ExtButtonProgress is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ExtButtonProgress", :git => 'https://github.com/AlexSmet/ExtButtonProgress.git'
Created by Alexander Smetannikov ([email protected]) Thanks to Evgeny Safronov
ExtButtonProgress is available under the MIT license. See the LICENSE file for more info.