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)
Animate the value of the Set slider
Slider.setvalue (0.5, animated:true)
Slider Value change response
Slider.iscontinuous = false///slider will not trigger valuechanged event after sliding stop
Slider.addtarget (Self, Action: #selector (Sliderchange (slider:)), for:. valuechanged)
The color of the left and right side slots of the slider
Slider.minimumtracktintcolor = uicolor.red
Slider.maximumtracktintcolor = Uicolor.green
Add an icon to the sides of the slider behind the Groove line
Slider.minimumvalueimage=uiimage (named: "2")//Left icon
Slider.maximumvalueimage=uiimage (named: "2")//Right icon
Set the picture of the slider
Slider.setthumbimage (UIImage (named: "2"), For:.normal)
}
Func Sliderchange (Slider:uislider) {
Print (Slider.value)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
Dispose of any resources the can be recreated.
}
}
Swift Practice---UISlider