Awesome Open Source
Awesome Open Source


A smooth, nice looking and IBDesignable flat design switch for iOS. Can be used instead of UISwitch.

Inspired by Creativedash's Dribbble post here

Flat switch animation



  • iOS 8.0+, tvOS 12.0+
  • Xcode 11.0+
  • Swift 5


Creating the flat switch

  • Either programmatically
var flatSwitch = AIFlatSwitch(frame: CGRectMake(0, 0, 50, 50))
  • Or in Interface Builder


To change its selected state:

flatSwitch.isSelected = true
  • [x] IBInspectable


flatSwitch.setSelected(true, animated: true)

To listen to its state changes:

@IBAction func handleSwitchValueChange(sender: AnyObject) {
		if let flatSwitch = sender as? AIFlatSwitch {

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 =
flatSwitch.trailStrokeColor =
flatSwitch.backgroundLayerColor =
flatSwitch.animatesOnTouch = false
  • [x] IBInspectable

Contribution guidelines

  • Make your changes in your branch
  • Bump the pod version in AIFlatSwitch.podspec file (e.g. 1.0.1 to 1.0.2)
  • Make sure the Example project compiles and works fine in the Simulator
  • Find references to your source code changes in and update them (e.g. method names, changed features)
  • Create a pull request


AIFlatSwitch is released under the MIT license. See LICENSE for details.

animated check button, checkmark

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Swift (65,929
Button (18,840
Animation (17,631
Material (15,964
Switch (8,225
Animated (3,906
Checkbox (1,983
Ibdesignable (178
Uiswitch (20
Checkmark (9