Ray0218 / SevenSwitch

iOS7 style drop in replacement for UISwitch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SevenSwitch

iOS7 style drop in replacement for UISwitch

Animation

Default

Usage

Cocoapods

pod 'SevenSwitch', '~> 2.0'

Currently Swift is not supported in Cocoapods. So 2.0 will not work. You should be using 1.4 for the time being. If you'd like to keep track of progress on Swift integration in Cocoapods you can see this issue

Without Cocoapods

Add SevenSwitch.swift to your project and add the QuartzCore framework to your project.

Examples

Initializing and adding the switch to the screen

let mySwitch = SevenSwitch()
self.view.addSubview(mySwitch)

When the user manipulates the switch control ("flips" it) a UIControlEvent.ValueChanged event is generated.

mySwitch.addTarget(self, action: "switchChanged:", forControlEvents: UIControlEvents.ValueChanged)

You can set images for the on/off states

mySwitch.offImage = UIImage(named: "cross.png")
mySwitch.onImage = UIImage(named: "check.png")
mySwitch.thumbImage = UIImage(named: "thumb.png")

You can set text for the on/off states

mySwitch.offLabel.text = "ON"
mySwitch.onLabel.text = "OFF"

You can also customize the switches colors

mySwitch.thumbTintColor = UIColor(red: 0.19, green: 0.23, blue: 0.33, alpha: 1)
mySwitch.activeColor =  UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch.inactiveColor =  UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch.onTintColor =  UIColor(red: 0.45, green: 0.58, blue: 0.67, alpha: 1)
mySwitch.borderColor = UIColor.clearColor()
mySwitch.shadowColor = UIColor.blackColor()

You can resize the switch frame to whatever you like to make fatter/skinnier controls

mySwitch.frame = CGRectMake(0, 0, 100, 50)

You can turn off the rounded look by setting the isRounded property to NO

mySwitch.isRounded = false

Swift and Objective-C compatability

SevenSwitch uses Swift as of its 2.0 release. SevenSwitch.swift can be used in Objective-C. See ViewController.m for an example.

Requirements

SevenSwitch requires iOS 5.0 and above.

ARC

SevenSwitch uses ARC as of its 1.0 release.

License

Made available under the MIT License. Attribution would be nice.

About

iOS7 style drop in replacement for UISwitch

License:MIT License