您的位置:首页 > 产品设计 > UI/UE

iOS5新控件UIStepper应用示例

2012-01-12 16:13 423 查看
在iOS5中增加了一个UIStepper的新控件,UIStepper可以连续增加或减少一个数值。控件的外观是两个水平并排的按钮构成,一个显示为“+”,一个显示为“-”。如下图所示:



该控件一个有趣的特征是当用户按住“+”“-”按钮时,根据按住的时间长度,控件值的数字也以不同的数字改变。按住的时间越长,数值改变的越快。可以为UIStepper设定一个数值范围,比如0-99。

下面是UIStepper应用范例代码:


// Create a label to show the value in the stepper
label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 100, 30)];
[label setTextColor:[UIColor whiteColor]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextAlignment:UITextAlignmentLeft];
[label setText: @"Quantity:"];
[[self view] addSubview:label];

// Frame defines location, size values are ignored
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)];

// Set action target and action for a particular value changed event
[stepper addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChanged];

// Set min and max
[stepper setMinimumValue:0];
[stepper setMaximumValue:99];

// Value wraps around from minimum to maximum
[stepper setWraps:YES];

// If continuos (default), changes are sent for each change in stepper,
// otherwise, change event occurs once user lets up on button
[stepper setContinuous:NO];

// To change the increment value for each step
// (default is 1)
[stepper setStepValue:10];


文章出处:http://www.ctolive.com/space-1023-do-blog-id-2068.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: