HPRangeSlider is a pod which helps to add slider to any UIVIew. It is written in Swift 4.
- Open podfile in your project.
- Add the following into your podfile:
pod ‘HPRangeSlider’, :git => ‘https://github.com/Harsh061/HPRangeSlider.git’, :tag => ‘1.0.0’
- Run the command:
pod install
- Open the project. Drag a UIView into storyboard.
- Go the the identity inspector and in the class field, type HPRangeSlider instead of UIView.
- Open the viewcontroller. Import HPRangeSlider.
import HPRangeSlider
- Create an outlet of the view.
@IBOutlet weak var rangeSlider: HPRangeSlider!
- Set your custom properties like sliderTitle, value, minValue, maxValue and handleTintColor.
private func setupSlider() {
rangeSlider.delegate = self
rangeSlider.sliderTitle = ""
rangeSlider.value = 0
rangeSlider.minValue = 0
rangeSlider.maxValue = 10
rangeSlider.handleTintColor = UIColor.red
}
- Confirm to the delegate method
extension ViewController: HPRangeSliderDelegate {
func rangeSlider(selectedValue: Float) {
print("Current value", selectedValue)
}
}