码迷,mamicode.com
首页 > 编程语言 > 详细

Swift - UIStepper

时间:2019-01-07 01:39:43      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:red   targe   frame   ntc   sel   pre   self   height   divide   

import UIKit

class ViewController: UIViewController{
    var stepper:UIStepper!
    var label:UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()
        //创建Stepper
        stepper = UIStepper(frame: CGRect(x: 150, y: 250, width: 100, height: 100))
        //设置最大值
        stepper.maximumValue = 10
        //设置最小值
        stepper.minimumValue = 0
        //设置初始值
        stepper.value = 1
        //设置递增减值
        stepper.stepValue = 0.5
        //设置是否可以按住连续更改值
        stepper.isContinuous = true
        //设置stepper是否循环(超过最大值从最小值开始)
        stepper.wraps = true
        //设置stepper颜色
        stepper.tintColor = UIColor.red
        //设置+-符号,背景,中间分隔线图片
        stepper.setDecrementImage(UIImage(named: "DecrementImage"), for: .normal)//设置-符号图片
        stepper.setIncrementImage(UIImage(named: "IncrementImage"), for: .normal)//设置+符号图片
        stepper.setBackgroundImage(UIImage(named:"BackImage"), for: .normal)
        stepper.setDividerImage(UIImage(named: "DividerImage"), forLeftSegmentState: .normal, rightSegmentState: .normal)//设置中间分割线图片
        //添加响应事件
        stepper.addTarget(self, action: #selector(ViewController.stepperValueChanged), for: .valueChanged)
        self.view.addSubview(stepper)
        label = UILabel(frame: CGRect(x: 150, y: 300, width: 300, height: 50))
        label.text = "当前值为:\(stepper.value)"
        self.view.addSubview(label)
    }
    @objc func stepperValueChanged()
    {
        label.text = "当前值为:\(stepper.value)"
    }
}

Swift - UIStepper

标签:red   targe   frame   ntc   sel   pre   self   height   divide   

原文地址:https://www.cnblogs.com/iOS-Development/p/10231000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!