滑杆
let slider = UISlider(frame:CGRect(x: 100, y: 50, width: 200, height: 40))
self.view.addSubview(slider)
//如果滑杆没有设置最小最大值,默认0~1
//给滑杆添加事件
slider.addTarget(self, action: #selector(sliderAction(slider:)), for: .valueChanged)
//设置滑杆最大值
slider.maximumValue = 100
//设置滑杆最小值
slider.minimumValue = 0
// //修改最小值颜色
// slider.minimumTrackTintColor = UIColor.gray
// slider.maximumTrackTintColor = UIColor.green
// //滑块颜色
// slider.thumbTintColor = UIColor.yellow
//自定义滑杆图片
let sliderImage = UIImage(named: "a.jpg")
let thumbImage = UIImage(named: "b.jpg")
slider.setMaximumTrackImage(sliderImage, for: .highlighted)
//设置滑杆划过区域的图片
slider.setMinimumTrackImage(sliderImage, for: .normal)
//例如音量的大小喇叭🎺
slider.minimumValueImage = sliderImage
slider.maximumValueImage = sliderImage
//当我们拖动滑杆时候会处于高亮状态
//松开处于正常状态
slider.setThumbImage(thumbImage, for: .normal)
slider.setThumbImage(thumbImage, for: .highlighted)
slider.value = 90
slider.maximumValueImage = UIImage(named: "1.png")
slider.minimumValueImage = UIImage(named: "3.png")
}
//滑杆的事件
func sliderAction(slider :UISlider){
print(slider.value)//value当前的值
}