微调器或叫步进器(UIStepper)

    var step : UIStepper!
    var label : UILabel!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        step = UIStepper(frame: CGRect(x: 100, y: 100, width: 200, height: 50))
        //设置stepper的范围与初始值
        step.maximumValue=10
        step.minimumValue=1
        step.value=5.5
        //设置每次增减的值
        step.stepValue=0.5
        //设置stepper可以按住不放来连续更改值
        step.isContinuous=true
        //设置stepper是否循环(到最大值时再增加数值从最小值开始)
        step.wraps=true
        step.addTarget(self, action:#selector(stepClick), for: .valueChanged)
        self.view.addSubview(step)
        
        
    }

    func stepClick()
    {
        print("\(step.value)")
    }

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