滑块
1. 创建
let Sli: UiSlider = UiSlider(frame: CGRectMake(10.0,270,300,5)) as UiSlider Sli.minimumValue = 10 Sli.maximumValue = 300 Sli.continuous = false
continous属性为true:滑块在滑动过程中响应事件,为false时则只在滑动后响应事件
2.设置各区域的图片
//滑块左边和右边的视图 Sli.setMinimumTrackImage(UIImage(named: "green.png"),forState: UIControlState.Normal) Sli.setMinimumTrackImage(UIImage(named: "green.png"),forState: UIControlState.Normal) //滑块的视图 //Sli.setThumbImage(UIImage(named: "green.png"),forState: UIControlState.Normal) //滑块最大值和最小值处的图片 //Sli.minimumValueImage = UIImage(named: "green.png") //Sli.maximumValueImage = UIImage(named: "green.png")
3.响应事件和Tag
Sli.addTarget(self,action: "Progress",forControlEvents: UIControlEvents.ValueChanged) Sli.tag = 2
4. 获取滑块的值
let prog:UiSlider = self.view.viewWithTag(2) as! UiSlider let a = prog.value
进度条
1创建
let Progress: UIProgressView = UIProgressView(frame: CGRectMake(10,3)) Progress.progress = 0.0 Progress.tag = 1
2.设置
let a = 50 aaa.setProgress(a/100,animated: false)
步进控件
1.创建
let stepPro: UIStepper = UIStepper(frame: CGRectMake(10,310,5)) stepPro.minimumValue = 0 stepPro.maximumValue = 100 stepPro.value = 0 stepPro.stepValue = 2.0
2.响应事件
stepPro.addTarget(self,action: "stepEven:",forControlEvents: UIControlEvents.TouchDown) stepPro.continuous = true stepPro.tag = 255
continuous属性UiSlider类似
3.获取步进的值
let setp: UIStepper = self.view.viewWithTag(255) as! UIStepper let a = setp.value NSLog("\(a)")原文链接:https://www.f2er.com/swift/326247.html