- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIStepper *stepper = [[UIStepper alloc] init];
stepper.tag = 100;
stepper.center = CGPointMake(160, 240);
stepper.minimumValue = 1; //设置最小值
stepper.maximumValue = 30; //设置最大值
stepper.stepValue = 2; //每次递增2
stepper.value = 15; //初始值
[stepper setWraps:YES]; //是否循环
[stepper addTarget:self action:@selector(Test) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:stepper];
}
-(void)Test
{
UIStepper *per = (UIStepper*)[self.view viewWithTag:100];
if (per.continuous)
{
NSLog(@"X");
int a = per.value; //获取当前值
NSLog(@"%d", a);
}
else
{
NSLog(@"N");
}
}
运行效果如下:
当每次点➕或者➖的时候 ,都会依次增加数值的变化。