标签:uistepper 计数器 ios 控件
这是iOS5后才出现的控件,镔哥做项目用过,所以列出来,UIStepper是一个类似UISwitch的控件,但是左右两边是一个加号和一个减号。它主要有下面几个属性
continuous
autorepeat
wraps
minimumValue
maximumValue
NSInvalidArgumentException 异常
stepValue
NSInvalidArgumentException 异常
value
tintColor
UIControlState 有六个枚举变量
enum {
UIControlStateNormal = 0, 正常情况
UIControlStateHighlighte
d = 1 << 0, 在作用域内点击但是没有松手
UIControlStateDisabled = 1 << 1, 禁止使用时
UIControlStateSelected = 1 << 2, 点击且松手一般是按钮按下且凹陷的状态
UIControlStateApplicatio
n = 0x00FF0000,额外的状态当应用程序使用时
UIControlStateReserved = 0xFF000000 内部框架使用
};
该控件一个有趣的特征是当用户按住“+”“-”按钮时,根据按住的时间长度,控件值的数字也以不同的数字改变。按住的时间越长,数值改变的越快。可以为UIStepper设定一个数值范围,比如0-99。
下面是UIStepper应用范例代码:
01 |
//
Create a label to show the value in the stepper |
02 |
label
= [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 100, 30)]; |
03 |
[label
setTextColor:[UIColor whiteColor]]; |
04 |
[label
setBackgroundColor:[UIColor clearColor]]; |
05 |
[label
setTextAlignment:UITextAlignmentLeft]; |
06 |
[label
setText: @ "Quantity:" ]; |
07 |
[[self
view] addSubview:label]; |
08 |
|
09 |
//
Frame defines location, size values are ignored |
10 |
UIStepper
*stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)]; |
11 |
|
12 |
//
Set action target and action for a particular value changed event |
13 |
[stepper
addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChang |
14 |
|
15 |
//
Set min and max |
16 |
[stepper
setMinimumValue:0]; |
17 |
[stepper
setMaximumValue:99]; |
18 |
|
19 |
//
Value wraps around from minimum to maximum |
20 |
[stepper
setWraps:YES]; |
21 |
|
22 |
//
If continuos (default), changes are sent for each change in stepper, |
23 |
//
otherwise, change event occurs once user lets up on button |
24 |
[stepper
setContinuous:NO]; |
25 |
|
26 |
//
To change the increment value for each step |
27 |
//
(default is 1) |
28 |
[stepper
setStepValue:10]; |
标签:uistepper 计数器 ios 控件
原文地址:http://blog.csdn.net/sammyieveo/article/details/41518587