Swift - UIStepper

1、

import UIKit
class ViewController: UIViewController{
    
    var stepper:UIStepper!
    var label:UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        stepper = UIStepper()
        stepper.center = self.view.center
        //设置stepper的初始值
        stepper.maximumValue = 10
        stepper.minimumValue = 1;
        stepper.value = 5.5
        //设置每次增减的值
        stepper.stepValue = 0.5
        //设置stepper可以按住不放来连续更改值
        stepper.isContinuous=true
        //设置stepper是否循环(最大值时再增加数值从最小值开始)
        stepper.wraps = true
        stepper.addTarget(self, action: #selector(stepperValueIschanged), for: .valueChanged)
        self.view.addSubview(stepper)
        label = UILabel(frame: CGRect(x: 100, y: 190, width: 300, height: 30))
        label.text = "当前值为\(stepper.value)"
        self.view.addSubview(label)
        
    }
   
    @objc func stepperValueIschanged(){
    
        label.text = "当前值为:\(stepper.value)"
    }
}

 微调器(UIStepper)控件包含两个按钮“+”和“-”

 

posted @ 2018-06-20 15:36  小白姐  阅读(202)  评论(0编辑  收藏  举报