项目介绍:
https://github.com/thehung111/NHRangeSlider
NHRangeSlider
A custom range slider in Swift. Forked from RangeSlider with some enhancements.
Swift中的自定义范围滑块。 增强版的 RangeSlider。
Requirements
-
iOS: 8.0+
-
Xcode 8.1+
-
Swift 3.0+
Installation
CocoaPods
CocoaPods 1.1.0+ is required to build NHRangeSlider.
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'NHRangeSlider', '~> 0.1.1'
end
Then, run the:
$ pod install
Carthage
Put the following in your Cartfile:
github "thehung111/NHRangeSlider" ~> 0.1.1
Run carthage update --platform iOS --no-use-binaries
Usage 使用方法
Default Slider 默认
By default, the title label is not shown and the left and right thumbs will be circles (curvaceousness
set to 1). You can add the view in code or via story board:
默认情况下,标题标签不显示,左右拇指将是圆圈(“curvaceousness”设置为1)。 您可以在代码或故事板中添加视图:
override func viewDidLoad() {
super.viewDidLoad()
// default slider. Configure the frame
let sliderView = NHRangeSliderView(frame: CGRect(x: 16, y: 20, width: self.view.bounds.width - 32, height: 80) )
// call size to fit to resize the height to fit exactly
sliderView.sizeToFit()
self.view.addSubview(sliderView)
}
Slider with Square Thumbs 自定义
let sliderSquareView = NHRangeSliderView(frame: ...)
// set to 0 for square
sliderSquareView.curvaceousness = 0.0
sliderSquareView.trackHighlightTintColor = UIColor.red
sliderSquareView.lowerValue = 20.0
sliderSquareView.upperValue = 80.0
sliderSquareView.sizeToFit()
self.view.addSubview(sliderSquareView)
Slider with title
let sliderSquareWithLabelView = NHRangeSliderView(frame: ...)
sliderSquareWithLabelView.curvaceousness = 0.0
sliderSquareWithLabelView.trackHighlightTintColor = UIColor.brown
sliderSquareWithLabelView.lowerValue = 20.0
sliderSquareWithLabelView.upperValue = 80.0
// set title text
sliderSquareWithLabelView.titleLabel?.text = "Slider with title label"
sliderSquareWithLabelView.sizeToFit()
self.view.addSubview(sliderSquareWithLabelView)
Slider with labels following thumbs
let sliderWithLabelFollowView = NHRangeSliderView(frame: ...)
sliderWithLabelFollowView.trackHighlightTintColor = UIColor.black
sliderWithLabelFollowView.lowerValue = 30.0
sliderWithLabelFollowView.upperValue = 70.0
sliderWithLabelFollowView.gapBetweenThumbs = 5
// set style to follow
sliderWithLabelFollowView.thumbLabelStyle = .FOLLOW
sliderWithLabelFollowView.titleLabel?.text = "Slider with labels follow thumbs"
sliderWithLabelFollowView.sizeToFit()
self.view.addSubview(sliderWithLabelFollowView)
API Reference
https://thehung111.github.io/NHRangeSlider/