滑动控件
添加下面的代码,实现基本功能
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//设置滑动控件的位置和大小
let slider = UISlider(frame: CGRect(x:20, y:100, width:280, height:30))
//设置是否连续触发,true->用户在滑动滑块时,触发方法就会多次执行,false->只有当用户滑动操作结束时,才会触发
slider.isContinuous = false
//最小值
slider.minimumValue = 0
//最大值
slider.maximumValue = 10
//滑块左边的颜色
slider.minimumTrackTintColor = UIColor.cyan
//滑块右边的颜色
slider.maximumTrackTintColor = UIColor.brown
//滑块的颜色
slider.thumbTintColor = UIColor.blue
//添加滑块滑动时的触发方法
slider.addTarget(self, action: #selector(changeValue), for: .valueChanged)
//滑动条最左侧设置图片
slider.minimumValueImage = UIImage(named:"2")
//滑动条最右侧设置图片
slider.maximumValueImage = UIImage(named:"2")
//滑块平常状态设置图片
slider.setThumbImage(UIImage(named:"2"), for:.normal)
self.view.addSubview(slider)
}