步进控件,可用于替换传统用于输入值的文本框。步进控件提供了“+”和“-”两个按钮,用来改变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];

}

步进控件——UIStepper的更多相关文章

  1. XF 滑块和步进控件

    <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http:/ ...

  2. UIStepper步进器 ——事件驱动型控件,(一个+和-按钮的)

    - (void)viewDidLoad {    [super viewDidLoad];        //步进器 固定的size (94*27), 事件驱动型控件    UIStepper *st ...

  3. UIStepper UISlider UISwitch UITextField 基本控件

    1.UIStepper 步进控件 必掌握 1.重要属性: .value 初始值 .maximumValue 最大值 .minimumValue 最小值 .stepValue 间隔 2.常用事件: Va ...

  4. [Xcode 实际操作]四、常用控件-(7)UIStepper控件的使用

    目录:[Swift]Xcode实际操作 本文将演示步进控件的基本用法.步进控件常用于小范围数值的调整. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import ...

  5. IOS之UIStepper控件详解

    在iOS5中新增了一个数字输入控件UIStepper,它可以递进式输入数量.UIStepper继承自UIControl,它主要的事件是UIControlEventValueChanged,每当它的值改 ...

  6. IOS开发之XCode学习013:步进器和分栏控件

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UIStepper和UISegmente ...

  7. swift系统学习控件篇:UIProgressView+NSTimer+UIstepper+UIAlertController

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIProgressView+NSTimer+UIstepper UIStepper UIP ...

  8. 【IOS 开发】基本 UI 控件详解 (UIDatePicker | UIPickerView | UIStepper | UIWebView | UIToolBar )

    转载注明出处 : http://blog.csdn.net/shulianghan/article/details/50348982 一. 日期选择器 (UIDatePicker) UIDatePic ...

  9. UI--普通控件总结1--控件使用

    本文目录 0.UIView常用的属性和操作 0_1.UIView常见的属性 0_2.UIView状态 0_3.UIView常用的方法 1.文本框UITextField和文本视图UITextView 1 ...

随机推荐

  1. JS的className,字体放大缩小

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  2. Air打包exe

    1.用flash创建一个airtest.fla,发布目标选择为AIR.ctrl+enter会得到如下文件: 2.把flex sdk的bin中找到adl.exe,复制过来,放置到:项目目录\bin\ad ...

  3. Linux学习 -- Shell编程 -- 正则表达式

    正则表达式与通配符 正则 -- 匹配字符串 -- 包含匹配     grep.awk.sed等 通配符 -- 匹配文件名 -- 完全匹配  ls.find.cp等 基础正则表达式

  4. ubuntu服务器移植步骤

    1.安装LAMP套件 1 tasksel 2.安装FTP工具 http://www.cnblogs.com/esin/p/3483646.html 3.安装PHPMyAdmin 1)安装 1 apt- ...

  5. messages exchanged between the client's and server's computers will never be lost, damaged, or received out of order. [1]

    w几乎所有的HTTP通信都由TCP/IP承载. HTTP The Definitive Guide Just about all of the world's HTTP communication i ...

  6. dotnet core error 0x80070057

    安装补丁KB2533623 https://support.microsoft.com/en-us/kb/2533623

  7. MJRefresh

    automaticallyChangeAlpha 下拉或上拉时,文字颜色逐渐加深

  8. Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'yintingting_baisi/Info.plist'.

    处理方法: The INFOPLIST_FILE build setting specifies the name of the Info.plist associated with your tar ...

  9. 8数码,欺我太甚!<bfs+康拓展开>

    不多述,直接上代码,至于康拓展开,以前的文章里有 #include<iostream> #include<cstdio> #include<queue> using ...

  10. editplus 常用

    个人习惯风格基本设置:document >preferences >fonts|( Comic sans MS  blod 18) -------------------- \n 去换行 ...