TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Mar 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Rafael Machado, Rafael Machado.
This control is inspired on this Creative Dash dribbble:
Use tags to fit your Swift version:
Swift 3 => 1.4
Swift 2.3 => 1.3
Just copy the OnOffButton.swift
into your project.
After the installation, you can use it straight in code or with xib/storyboard.
class ViewController: UIViewController {
let onOffButton = OnOffButton()
override func viewDidLoad() {
super.viewDidLoad()
onOffButton.frame = CGRect(origin: .zero, size:CGSize(width: 100,height: 100))
// Adjust properties
onOffButton.lineWidth = 5
onOffButton.strokeColor = .whiteColor()
onOffButton.ringAlpha = 0.3
onOffButton.addTarget(self, action: #selector(ViewController.didTapOnOffButton), forControlEvents: .TouchUpInside)
view.addSubview(onOffButton)
}
func didTapOnOffButton() {
onOffButton.checked = !onOffButton.checked
}
}
@IBDesignables
Set the UIButton
class to use OnOffButton
:
Configure the properties as you want:
Create an IBAction
:
@IBAction func changeButtonState(sender: OnOffButton) {
sender.checked = !sender.checked
}
Profit ;)
Released under the MIT license. See the LICENSE file for more info.