标签:
创建并设置相关属性
var stepper : UIStepper!//微调器 var label : UILabel!
stepper = UIStepper() stepper.frame = CGRectMake(50, 200, 280, 50) stepper.minimumValue = 0//最小值 stepper.maximumValue = 10;//最大值 stepper.value = 3//初值 stepper.stepValue = 1//每次增减的大小 stepper.continuous = true//长按是否可以连续改变值 stepper.wraps = false//时候可以循环 stepper.tintColor = UIColor.redColor()//设置整体色调 //用自定义的图片替换“-”和“+” stepper.setDecrementImage(UIImage(named: "-1"), forState: UIControlState.Normal) stepper.setIncrementImage(UIImage(named: "+1"), forState: UIControlState.Normal) stepper.addTarget(self, action: Selector("stepperDidChange"), forControlEvents: UIControlEvents.ValueChanged) self.view.addSubview(stepper)
用一个Label显示
label = UILabel(frame: CGRectMake(50, 50, 280, 50)) label.text = "stepper的值为\(stepper.value)" self.view.addSubview(label)
当微调器 的数值发生变化时刷新Label
func stepperDidChange(){ label.text = "stepper的值为\(stepper.value)" }
标签:
原文地址:http://www.cnblogs.com/spaceID/p/4977171.html