在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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. }
}
|
请发表评论