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];

    }

  • 相关阅读:
    jQuery动态加载动画spin.js
    jQuery自动过滤单词插件
    基于jQuery的自定义滚动条
    jQuery纵向分类下拉菜单导航
    仿酷狗官网新闻焦点图插件
    metro扁平UI网页组件
    HTML5环形音乐播放器
    纯CSS3个性化圆形按钮登录表单
    纯CSS3绘制的黑色图标按钮组合
    纯CSS3实现iOS7扁平化图标
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4721178.html
Copyright © 2011-2022 走看看