/AIFlatSwitch

A flat component alternative to UISwitch on iOS

Primary LanguageSwiftMIT LicenseMIT

AIFlatSwitch

A smooth, nice looking and IBDesignable animated flat switch component for iOS

Inspired by Creativedash's Dribbble post here








##Requirements

  • iOS 7.1+
  • Xcode 6.1

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', '~> 0.0.1'

Then, run the following command:

$ pod install

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.selected = true
  • IBInspectable

or:

flatSwitch.setSelected(true, animated: true)

To listen to its state changes:

@IBAction func onSwitchValueChange(sender: AnyObject) {
		if let flatSwitch = sender as? AIFlatSwitch {
			println(flatSwitch.selected)
		}
	}

Styling the switch:

flatSwitch.lineWidth = 2.0
flatSwitch.strokeColor = UIColor.blueColor()
flatSwitch.trailStrokeColor = UIColor.redColor()
  • IBInspectable

License

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