它主要有下面幾個屬性
continuous
autorepeat
wraps
minimumValue
maximumValue
NSInvalidArgumentException異常
stepValue
NSInvalidArgumentException異常
value
tintColor
UIControlState 有六個枚舉變量
enum {
UIControlStateNormal = 0, 正常情況
UIControlStateHighlighted = 1 << 0, 在作用域內點擊但是沒有松手
UIControlStateDisabled = 1 << 1, 禁止使用時
UIControlStateSelected = 1 << 2, 點擊且松手一般是按鈕按下且凹陷的狀態
UIControlStateApplication = 0x00FF0000,額外的狀態當應用程序使用時
UIControlStateReserved = 0xFF000000 內部框架使用
};
該控件一個有趣的特征是當用戶按住“+”“-”按鈕時,根據按住的時間長度,控件值的數字也以不同的數字改變。按住的時間越長,數值改變的越快。可以為UIStepper設定一個數值范圍,比如0-99。
下面是UIStepper應用范例代碼:
//
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:UIControlEventValueChanged];
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];