Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cocoatoucher/aiflatswitch
Nicely animated flat design switch alternative to UISwitch
https://github.com/cocoatoucher/aiflatswitch
animated animation button checkbox checkmark custom design flat material smooth swift switch uiswitch
Last synced: about 3 hours ago
JSON representation
Nicely animated flat design switch alternative to UISwitch
- Host: GitHub
- URL: https://github.com/cocoatoucher/aiflatswitch
- Owner: cocoatoucher
- License: mit
- Created: 2015-04-03T16:41:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-06-06T00:00:45.000Z (over 2 years ago)
- Last Synced: 2024-04-24T18:57:37.994Z (7 months ago)
- Topics: animated, animation, button, checkbox, checkmark, custom, design, flat, material, smooth, swift, switch, uiswitch
- Language: Swift
- Homepage:
- Size: 136 KB
- Stars: 983
- Watchers: 25
- Forks: 65
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](http://dribbble.com/shots/1631598-On-Off)
## Requirements
- iOS 8.0+, tvOS 12.0+
- Xcode 11.0+
- Swift 5## Usage
### Creating the flat switch
- Either programmatically
```swift
var flatSwitch = AIFlatSwitch(frame: CGRectMake(0, 0, 50, 50))
```- Or in Interface Builder
### Methods
> To change its selected state:
```swift
flatSwitch.isSelected = true
```
- [x] IBInspectable> or:
```swift
flatSwitch.setSelected(true, animated: true)
```> To listen to its state changes:
```swift
@IBAction func handleSwitchValueChange(sender: AnyObject) {
if let flatSwitch = sender as? AIFlatSwitch {
print(flatSwitch.isSelected)
}
}
```> Animation observer callbacks:
```swift
flatSwitch.selectionAnimationDidStart = { isSelected in
print("New state: \(isSelected)")
}flatSwitch.selectionAnimationDidStop = { isSelected in
print("State when animation stopped: \(isSelected)")
}
```> Styling the switch:
```swift
flatSwitch.lineWidth = 2.0
flatSwitch.strokeColor = UIColor.blue
flatSwitch.trailStrokeColor = UIColor.red
flatSwitch.backgroundLayerColor = UIColor.red
flatSwitch.animatesOnTouch = false
```
- [x] 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 sure the Example project compiles and works fine in the Simulator
- 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