Toggler
Intoduction
isSelected
to every button. use Toggler
to simply control your buttons
Don't do like these any more
func buttonClicked(_ sender: UIButton) {
switch sender.tag {
case 0:
button1.isSelected = true
button2.isSelected = false
button3.isSelected = false
button4.isSelected = false
button5.isSelected = false
case 1:
button1.isSelected = false
button2.isSelected = true
button3.isSelected = false
button4.isSelected = false
button5.isSelected = false
case 2:
button1.isSelected = false
button2.isSelected = false
button3.isSelected = true
button4.isSelected = false
button5.isSelected = false
case 3:
button1.isSelected = false
button2.isSelected = false
button3.isSelected = false
button4.isSelected = true
button5.isSelected = false
case 4:
button1.isSelected = false
button2.isSelected = false
button3.isSelected = false
button4.isSelected = false
button5.isSelected = true
default:
break
}
}
Toggler
Use func buttonClicked(_ sender: UIButton) {
toggler.on(toggle: sender)
}
Requirements
Toggler
is written in Swift 3. Compatible with iOS 8.0+
Installation
Cocoapods
Toggler is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Toggler'
Carthage
github "younatics/Toggler"
Usage
Init with UIButton
or UISwtich
and default index
toggler = Toggler(default: 0, togglers: [button1, button2, button3, button4, button5])
Toggle button
toggler.on(toggle: sender)
toggler.onAt(index: sender.tag)
Add more button
toggler.add(toggle: button6)
Remove button
toggler.remove(at: 5)
References
Please tell me or make pull request if you use this library in your application :)
Author
License
Toggler is available under the MIT license. See the LICENSE file for more info.