A custom Range Slider for OSX
JMSRangeSlider is a range slider for OSX, written in Swift 2 and built with Xcode 7.
You can define its minimum & maximum values, its lower & upper values, its direction (horizontal / vertical), the side of its cells (left / right / top / bottom of the track bar), the width & height of the cells, the tint & highlight colors of the track bar, the cells' colors and wether or not the cells and track bar have a corner radius.
- OS 10.10+
- Swift 2
Add the following line to your Podfile
:
target 'MyApp' do
use_frameworks!
pod 'JMSRangeSlider'
end
Copy the folder JMSRangeSlider
to your project
let rangeSlider: JMSRangeSlider = JMSRangeSlider(frame: CGRectZero)
rangeSlider.direction = JMSRangeSliderDirection.Vertical
rangeSlider.cellsSide = JMSRangeSliderCellsSide.Left
rangeSlider.cellWidth = 20
rangeSlider.cellHeight = 30
rangeSlider.trackThickness = 10
rangeSlider.minValue = 0
rangeSlider.maxValue = 100
rangeSlider.lowerValue = 25
rangeSlider.upperValue = 75
rangeSlider.trackHighlightTintColor = NSColor(red: 0.4, green: 0.698, blue: 1.0, alpha: 1.0)
rangeSlider.frame = CGRect(x: 20.0, y: 20.0, width: self.bounds.width, height: 30.0)
rangeSlider.action = "updateRange:"
rangeSlider.target = self
self.addSubview(rangeSlider)
func updateRange(sender: AnyObject) {
NSLog("Lower value = \(rangeSlider.lowerValue)")
NSLog("Upper value = \(rangeSlider.upperValue)")
}
Direction of the slider ( Horizontal / Vertical )
Type JMSRangeSliderDirection
Optional
Default: JMSRangeSliderDirection.Horizontal
Side of the cells ( Top / Bottom / Left / Right )
Type JMSRangeSliderCellsSide
Optional
Default:
JMSRangeSliderCellsSide.Top
when direction = JMSRangeSliderDirection.Horizontal
JMSRangeSliderCellsSide.Left
when direction = JMSRangeSliderDirection.Vertical
Width of the cells
Type CGFloat
Optional
Default: 20.0
Height of the cells
Type CGFloat
Optional
Default: 20.0
Minimum value
Type Double
Optional
Default: 0
Maximum value
Type Double
Optional
Default: 1
Initial lower value
Type Double
Optional
Default: 0
Initial upper value
Type Double
Optional
Default: 1
Tint color of track
Type NSColor
Optional
Default: rgba(0.8, 0.8, 0.8, 1)
Highlight tint color of track
Type NSColor
Optional
Default: rgba(0, 0, 0, 1)
Tint color of cells
Type NSColor
Optional
Default: white
Corner radius of cell
Type CGFloat
Optional
Default: 1
There's a demo project in the repo
MIT License