Skip to content
Nicely animated flat design switch alternative to UISwitch
Branch: master
Clone or download
Latest commit 6684aa0 Mar 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
AIFlatSwitch.xcodeproj Update to Swift 4 Nov 12, 2018
AIFlatSwitch Reorganised pod structure Sep 17, 2016
Example Use fillColor instead of backgroundColor Mar 18, 2019
Source Use fillColor instead of backgroundColor Mar 18, 2019
AIFlatSwitch.podspec Added inner color Mar 17, 2019


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

Inspired by Creativedash's Dribbble post here

Platform Language License


  • iOS 8.0+
  • Xcode 8.0+ (Use pod version 0.0.4 for Xcode 7)
  • Swift 4.2+ (Use pod version 0.0.4 for Swift 2.3, Use pod version 1.0.3 for Swift 3)


Embedded frameworks require a minimum deployment target of iOS 8.

To use with a project targeting iOS 7, you must include the AIFlatSwitch.swift source file directly in your project.


CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

To integrate AIFlatSwitch into your Xcode project using CocoaPods, specify it in your Podfile:

source ''
platform :ios, '8.0'

pod 'AIFlatSwitch', '~> 1.0.6'

Then, run the following command:

$ pod install


  1. Download and drop AIFlatSwitch.swift in your project.
  2. Congratulations!


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
  • 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
  • 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 a pod install in Example project to update its dependency to new framework version you just created
  • Make sure the Example project compiles and works fine in the Simulator
  • Find podspec version references in and update them (e.g. Cocoapods section)
  • 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

You can’t perform that action at this time.