Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bvogelzang/SevenSwitch
iOS7 style drop in replacement for UISwitch
https://github.com/bvogelzang/SevenSwitch
Last synced: 5 days ago
JSON representation
iOS7 style drop in replacement for UISwitch
- Host: GitHub
- URL: https://github.com/bvogelzang/SevenSwitch
- Owner: bvogelzang
- License: mit
- Created: 2013-06-11T06:36:34.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-01-02T12:17:15.000Z (almost 6 years ago)
- Last Synced: 2024-04-24T18:57:37.064Z (8 months ago)
- Language: Swift
- Homepage:
- Size: 1.09 MB
- Stars: 778
- Watchers: 43
- Forks: 201
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - SevenSwitch - iOS7 style drop in replacement for UISwitch. (UI / Switch)
- awesome-ios-star - SevenSwitch - iOS7 style drop in replacement for UISwitch. (UI / Switch)
- awesome - SevenSwitch - iOS7 style drop in replacement for UISwitch (etc)
- awesome - SevenSwitch - iOS7 style drop in replacement for UISwitch (etc)
README
## SevenSwitch
iOS7 style drop in replacement for UISwitch
![Animation](https://raw.github.com/bvogelzang/SevenSwitch/master/ExampleImages/example.gif)
![Default](https://raw.github.com/bvogelzang/SevenSwitch/master/ExampleImages/example.png)
## Usage
### Cocoapods
```
pod 'SevenSwitch', '~> 2.1'
```*Swift support was added in version `2.0`. If your project does not support swift you can use `1.4`.*
### 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
```swift
let mySwitch = SevenSwitch()
self.view.addSubview(mySwitch)
```When the user manipulates the switch control ("flips" it) a `UIControlEvents.valueChanged` event is generated.
```swift
mySwitch.addTarget(self, action: #selector(ViewController.switchChanged(_:)), for: UIControlEvents.valueChanged)
```You can set images for the on/off states
```swift
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
```swift
mySwitch.offLabel.text = "ON"
mySwitch.onLabel.text = "OFF"
```You can also customize the switches colors
```swift
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.clear
mySwitch.shadowColor = UIColor.black
```You can resize the switch frame to whatever you like to make fatter/skinnier controls
```swift
mySwitch.frame = CGRect(x: 0, y: 0, width: 100, height: 50)
```You can turn off the rounded look by setting the `isRounded` property to `false`
```swift
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](SevenSwitchExample/SevenSwitchExample/ViewController.m) for an example.
## Requirements
SevenSwitch requires iOS 8.0 and above.
#### ARC
SevenSwitch uses ARC as of its 1.0 release.
## License
Made available under the MIT License. Attribution would be nice.