zoukankan      html  css  js  c++  java
  • 步进控件——UIStepper

      步进控件,可用于替换传统用于输入值的文本框。步进控件提供了“+”和“-”两个按钮,用来改变stepper内部value的增加或减少,调用的事件是UIControlEventValueChanged。由于它是不显示值的,所以它一般是和label配合使用。

      stepper常用的属性有:

      (1) value属性:stepper的当前值

      (2)minimumValue属性:stepper的最小值

      (3)maximumValue属性:stepper的最大值

      (4)stepValue属性:stepper每步的大小

      (5)continuous属性:按住按钮,连续跳动过程中,中间值是否显示。默认是YES

      (6)autorepeat属性:按住按钮,是否能连续跳动。默认是YES

      (7)wraps属性:stepper的值达到最小或最大值时,是否可循环。默认是NO

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        //创建一个label用来显示stepper的值

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 40)];

        label.tag = 111;

        label.textAlignment = NSTextAlignmentCenter;

        [self.view addSubview:label];

        

        //创建stepper控件,并指定它的位置

        UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 150, 0, 0)];

        //指定stepper的最小值为0

        stepper.minimumValue = 0;

        //指定stepper的最大值为10

        stepper.maximumValue = 10;

        //指定stepper跳动的幅度为2

        stepper.stepValue = 2;

        //指定stepper的初始值为5

        stepper.value = 5;

        label.text = [NSString stringWithFormat:@"%f",stepper.value];

        

        //设定连续跳动过程中,中间值显示

        stepper.continuous = YES;

        //设定stepper能连续跳动

        stepper.autorepeat = YES;

        //设定stepper的值可循环

        stepper.wraps = YES;

        

        //当stepper的value改变时,调用方法。

        [stepper addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];

        [self.view addSubview:stepper];

    }

    - (void)valueChange:(UIStepper*)stepper {

        UILabel *label = (UILabel*)[self.view viewWithTag:111];

        label.text = [NSString stringWithFormat:@"%f",stepper.value];

    }

  • 相关阅读:
    Echarts 实现中国地图并轮播指定的地区?
    Linux安装Zookeeper
    初遇携程apollo配置中心
    eclipse安装lombok
    依赖layui form模块 复选框tree插件(拓展可根据属性单选还是多选,数据反选)
    centos7环境下mysql5.7的安装与配置
    中文算数验证码(加减乘除)
    获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址;
    jdk自带的MD5进行数据的加密与解密
    MyBatis-plus 代码生成器
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4721178.html
Copyright © 2011-2022 走看看