Skip to content
Nicely animated flat design switch alternative to UISwitch
Branch: master
Clone or download
Latest commit 6684aa0 Mar 22, 2019
Permalink
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
AIFlatSwitchTests
Example Use fillColor instead of backgroundColor Mar 18, 2019
Source Use fillColor instead of backgroundColor Mar 18, 2019
.gitignore
.swift-version
AIFlatSwitch.podspec Added inner color Mar 17, 2019
LICENSE
README.md

README.md

AIFlatSwitch

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








Requirements

  • 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)

Installation

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

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 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'AIFlatSwitch', '~> 1.0.6'

Then, run the following command:

$ pod install

Manually

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

Usage

Creating the flat switch

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

Methods

To change its selected state:

flatSwitch.isSelected = true
  • IBInspectable

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
  • 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 README.md and update them (e.g. Cocoapods section)
  • Find references to your source code changes in README.md and update them (e.g. method names, changed features)
  • Create a pull request

License

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

animated check button, checkmark

You can’t perform that action at this time.