文档中的一些属性和方法:
例子:
testStepper.stepValue = 10;
testStepper.minimumValue = 0;
testStepper.maximumValue = 55;
testStepper.value = 10;
testStepper.tintColor = [UIColor redColor];
testStepper.wraps = YES;
一开始就一直点加,则值的变化为 20 30 40 50 55
一开始就一直点减,则值的变化为 0
当到达上限或下限时,且wraps没有设置成YES,则相应的加或减的按钮会disable
该控件一个有趣的特征是当用户按住“+”“-”按钮时,根据按住的时间长度,控件值的数字也以不同的数字改变。按住的时间越长,数值改变的越快。可以为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]; |
09 |
//
Frame defines location, size values are ignored |
10 |
UIStepper
*stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)]; |
12 |
//
Set action target and action for a particular value changed event |
13 |
[stepper
addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChanged]; |
16 |
[stepper
setMinimumValue:0]; |
17 |
[stepper
setMaximumValue:99]; |
19 |
//
Value wraps around from minimum to maximum |
20 |
[stepper
setWraps:YES]; |
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]; |
26 |
//
To change the increment value for each step |
28 |
[stepper
setStepValue:10]; |