RangeSlider is a clean, simple, and attractive range-based slider control for Mac, written in Swift.
It is similar to NSSlider except that it affords two control points (start and end knobs), useful when users need to select a range of values.
Features:
- Simple, easy-to-use
- Flexible resizing
- Customizable
- Snap-to-interval (optional)
- Several built-in styles
- Add to XIB or create programmatically. Example:
let slider = RangeSlider(frame:sliderFrame)
- (Optional) Set the min/max values (default:
0.0-1.0
) - (Optional) Set the
start
/end
values (default:0.0-1.0
) - (Optional) Enable snapping (
snapsToIntegers = true
) - (Optional) Adjust style options (
colorStyle
,knobStyle
)
Once the slider is configured, you can respond to changes by observing the start
/end
(or length
) values, or using the onControlChanged
property.
Example:
mySlider.onControlChanged = {
(slider: RangeSlider) -> Void in
print("Slider changed! Start:\(slider.start) End:\(slider.end) Range:\(slider.length)")
}
RangeSlider is still a work-in-progress. A few of the known issues / ToDo's remaining:
- Fix clipping of knob shadows, especially for circular slider style
- General cleanup, refactoring
- Fix knobs being allowed to overlap
- Improve border stroke of circular knob style
- Accessibilty support + highlighting/focus and other control behaviors
RangeSlider is currently macOS-only, however it could easily be updated to work with UIKit. Please file an Issue or feel free to submit a Pull Request if you'd like iOS support.
Matt Reagan - Website: http://sound-of-silence.com/ - Twitter: @hmblebee
RangeSlider's source code and related resources are Copyright (C) Matthew Reagan 2016. The source code is released under the MIT License. If you use RangeSlider in any publicly-distributed applications please include attribution.