标签:imp uiview 滑块 animate 图标 set port 响应 pos
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let slider = UISlider.init(frame: CGRect.init(x: 0, y: 0, width: 300, height: 50))
slider.center = self.view.center
slider.minimumValue = 0
slider.maximumValue = 1
slider.value = 0.5
self.view.addSubview(slider)
// 设置滑块的值 有动画
slider.setValue(0.5, animated: true)
// 滑块值改变响应
slider.isContinuous = false // 滑块滑动停止之后才会触发 ValueChanged 事件
slider.addTarget(self, action: #selector(sliderChange(slider:)), for: .valueChanged)
// 滑块左右两边槽的颜色
slider.minimumTrackTintColor = UIColor.red
slider.maximumTrackTintColor = UIColor.green
// 滑块后面槽线两侧添加图标
slider.minimumValueImage=UIImage(named:"2") //左边图标
slider.maximumValueImage=UIImage(named:"2") //右边图标
//设置滑块的图片
slider.setThumbImage(UIImage(named:"2"),for:.normal)
}
func sliderChange(slider:UISlider){
print(slider.value)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
标签:imp uiview 滑块 animate 图标 set port 响应 pos
原文地址:http://www.cnblogs.com/dingzhijie/p/6973175.html