UISlider 滑竿
let slider = UISlider(frame: CGRect(x: 100, y: 50, width: 200, height: 40))
self.view.addSubview(slider)
//如果滑块没有设置最小值,最大值,默认是0和1
//设置最小值
slider.minimumValue = 1
//设置最大值
slider.maximumValue = 100
// 给滑块添加事件
slider.addTarget(self, action: #selector(sliderAction(slider:)), for: .valueChanged)
//设置滑块样式,设置滑块两边的颜色
slider.minimumTrackTintColor = UIColor.red
slider.maximumTrackTintColor = UIColor.green
//修改滑块上按钮的颜色
slider.thumbTintColor = UIColor.yellow
//为滑块两端增加图标
slider.minimumValueImage = UIImage(named:"-.png")
slider.maximumValueImage = UIImage(named:"+.png")
//设置滑块的图片
slider.setThumbImage(UIImage(named:"button.jpg"), for: .highlighted)
//slider.setThumbImage(UIImage(named:"button"), for: .highlighted)
slider.setMinimumTrackImage(UIImage(named:"1.jpg"), for: .normal)
slider.setMaximumTrackImage(UIImage(named:"1.jpg"), for: .normal)
// //自定义滑块的图片
// let sliderImage = UIImage(named:"1.jpg")
// let thumbImage = UIImage(named:"button")
// slider.minimumTrackImage(for: .normal)
}
func sliderAction(slider:UISlider) {
print(slider.value)
}