https://github.com/joncardasis/sizeslidebutton
A fun Swift UIControl for picking a size
https://github.com/joncardasis/sizeslidebutton
animation button cocoapods control ios-animation picker size slide slider slider-animation swift swift-uicontrol
Last synced: 6 months ago
JSON representation
A fun Swift UIControl for picking a size
- Host: GitHub
- URL: https://github.com/joncardasis/sizeslidebutton
- Owner: joncardasis
- License: mit
- Created: 2016-07-27T13:52:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-14T14:50:01.000Z (about 8 years ago)
- Last Synced: 2024-12-19T20:36:09.532Z (6 months ago)
- Topics: animation, button, cocoapods, control, ios-animation, picker, size, slide, slider, slider-animation, swift, swift-uicontrol
- Language: Swift
- Homepage:
- Size: 547 KB
- Stars: 52
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SizeSlideButton



A fun Swift UIControl for picking a size.
## Installation
### Cocoapods
Add `pod 'SizeSlideButton'` to your Podfile.
### Manually
Add the `SizeSlideButton.swift` class to your project.## Examples
```Swift
let condensedFrame = CGRect(x: 280, y: 70, width: 32, height: 32) //Width and Height should be equal
let fancyControl = SizeSlideButton(condensedFrame: condensedFrame)fancyControl.trackColor = UIColor(red: 38/255, green: 50/255, blue: 56/255, alpha: 1)
fancyControl.handle.color = UIColor.white
fancyControl.addTarget(self, action: #selector(newSizeSelected), for: .touchDragFinished)
fancyControl.addTarget(self, action: #selector(sizeSliderTapped), for: .touchUpInside)
self.view.addSubview(fancyControl)func newSizeSelected(_ sender: SizeSlideButton){
//Do something once a size is selected and the control let go
// You can now use the senders .value for a value between 0 and 1
// Or use the handle's height (handle.height) as a multiplier for size
print("Value: \(sender.value)")
print("Size multiplier: \(sender.handle.height)")// Ex: self.paintbrush.brushSize = kDefaultBrushSize * sender.handle.height
}func sizeSliderTapped(_ sender: SizeSlideButton){
//Do something when the button is tapped
print("Tip Tap")
}
```
Output:
### Via Interface Builder
SizeSlideButton can also be created right from the Interface Builder and allows basic properties to be edited.## Documentation
+ `init(condensedFrame: CGRect)` will set the frame of where the condensed frame should lie (width and height should be equal)
+ `init(frame: CGRect)` will set the frame of where the frame should lie when fully expanded
+ `currentSize` to obtain the size the person has selected
+ `handlePadding` sets the padding around the handle (default is the left side's radius). Works best as <= leftSideRadius
+ `handle.color` is the slider's handle color
+ `handle.height`/`handle.width` gets the sizes of the handle and can be best used as a multiplier against a constant default size
+ `trackColor` is the color of the track
+ `value` is a value between 0 and 1.0 of where the handle was positioned relative on the track
+ `leftSideRadius` and `rightSideRadius` return the radii of the left and right sides of the frame when expanded
+ `currentState` returns if the control is condensed or expanded
+ `animationType` specifies the animation type used when letting go of the control## Supported UIControlEvents
+ `touchUpInside` is called when a tap on the control is released
+ `valueChanged` is called when the slider is moved
+ `touchDown` is called both when a long press is detected or a regular touch is detected
+ `touchDragFinished` (A custom UIControlEvent) is called when the slider has selected a new value and been released## License
SizeSlideButton is available under the MIT license. See the LICENSE file for more info.