Nicely animated flat design switch alternative to UISwitch
A smooth, nice looking and IBDesignable flat design switch for iOS. Can be used instead of UISwitch.
Inspired by Creativedash’s Dribbble post here
var flatSwitch = AIFlatSwitch(frame: CGRectMake(0, 0, 50, 50))
To change its selected state:
flatSwitch.isSelected = true
or:
flatSwitch.setSelected(true, animated: true)
To listen to its state changes:
@IBAction func handleSwitchValueChange(sender: AnyObject) {
if let flatSwitch = sender as? AIFlatSwitch {
print(flatSwitch.isSelected)
}
}
Animation observer callbacks:
flatSwitch.selectionAnimationDidStart = { isSelected in
print("New state: \(isSelected)")
}
flatSwitch.selectionAnimationDidStop = { isSelected in
print("State when animation stopped: \(isSelected)")
}
Styling the switch:
flatSwitch.lineWidth = 2.0
flatSwitch.strokeColor = UIColor.blue
flatSwitch.trailStrokeColor = UIColor.red
flatSwitch.backgroundLayerColor = UIColor.red
flatSwitch.animatesOnTouch = false
AIFlatSwitch is released under the MIT license. See LICENSE for details.
animated check button, checkmark