Swift 微调器或叫步进器(UIStepper)的用法

import UIKit

class ViewController: UIViewController   {
var stepper : UIStepper!
var lable : UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

    var SCREEN_WIDTH  = self.view.frame.width
    var SCREEN_HIGHT = self.view.frame.height

    stepper = UIStepper()
    stepper = UIStepper(frame: CGRectMake(0,230,100,30))
    //设置stepper的范围与初始值
    stepper.maximumValue = 10
    stepper.minimumValue = 1
    stepper.value = 5.5
    //设置每次增减值
    stepper.stepValue = 0.5
    //设置stepper按住连续改值
    stepper.continuous = true
    //设置stepper是否循环
    stepper.wraps = true
    stepper.addTarget(self, action: "stepperValueIschanged", forControlEvents: UIControlEvents.TouchUpInside)

    self.view.addSubview(stepper)
    lable = UILabel()
    lable = UILabel( frame: CGRectMake(100,230,100,30))
    print(stepper.value)
    lable.text = "当前值为:\(stepper.value)"

    self.view.addSubview(lable)
    
//使用tintColor属性可以设置微调器的颜色。 而加减符号图标,背景图片,中间分割线图片都可以替换成自己图片
    stepper.tintColor = UIColor .redColor()
    stepper.setDecrementImage(UIImage(named: ""), forState: UIControlState.Normal)
    stepper.setIncrementImage(UIImage(named: ""), forState: UIControlState.Normal)
}


func stepperValueIschanged(){
    
    lable.text = "当前值为:\(stepper.value)"
    print("当前值为:\(stepper.value)")
  }




}

你可能感兴趣的:(Swift 微调器或叫步进器(UIStepper)的用法)