UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 200, 0, 0)];
stepper.minimumValue = 30;
stepper.maximumValue = 10;
stepper.value = 20;
stepper.stepValue = 2;
// 是否循环
stepper.wraps = YES;
[stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
stepper.tag = 10;
[self.view addSubview:stepper];
[stepper release];
}
- (void)stepperAction:(id)stepper
{
UIStepper *ste = (UIStepper *)[self.view viewWithTag:10];
int a = ste.value;
NSLog(@"%d",a);
}
运行效果:
本文介绍如何使用UIStepper控件设置其属性如最小值、最大值、当前值及步长,并实现循环增减功能。同时展示了如何通过Objective-C为UIStepper添加事件监听,以便在值改变时执行特定操作。
5183

被折叠的 条评论
为什么被折叠?



