UIStepper

作者: CaptainRoy | 来源:发表于2019-09-25 17:13 被阅读0次
    class ViewController: UIViewController {
        
        var stepper:UIStepper!
        var label:UILabel!
    
        override func viewDidLoad() {
            
            super.viewDidLoad()
            
            stepper = UIStepper(frame: CGRect(x: 60.0, y: 60.0, width: 100.0, height: 100.0))
            stepper.maximumValue = 10
            stepper.minimumValue = 1
            stepper.stepValue = 0.5 // 每次增减的值
            stepper.isContinuous = true // 连续按动
            stepper.wraps = true // 到最大值时是否循环
            stepper.addTarget(self, action: #selector(stepperValueChanged(stepper:)), for: .valueChanged)
            self.view.addSubview(stepper)
            
            label = UILabel(frame: CGRect(x: 60.0, y: 200.0, width: 100.0, height: 200.0))
            label.font = UIFont.systemFont(ofSize: 10.0)
            label.text = "当前值为: \(stepper.value)"
            self.view.addSubview(label)
        }
        
        @objc func stepperValueChanged(stepper:UIStepper) ->Void {
            label.text = "当前值为: \(stepper.value)"
        }
        
    }
    

    相关文章

      网友评论

          本文标题:UIStepper

          本文链接:https://www.haomeiwen.com/subject/gdzquctx.html