- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
[self createStepper];
[self createLabel];
}
- (void)createLabel{
_label = [[UILabel alloc] initWithFrame:CGRectMake(100, 70, 50, 50)];
_label.text = @"10";
_label.backgroundColor = [UIColor greenColor];
_label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:_label];
}
- (void)createStepper{
//stepper 不受宽、高的影响、是固定的
UIStepper * stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
//设置最小值
stepper.minimumValue = 10;
//最大值
stepper.maximumValue = MAXFLOAT;
//设置每次增加的单位大小
stepper.stepValue = 10;
//长按速度加快
stepper.continuous = YES;
//加到最大变成最小值 减到最小值变成最大值
stepper.autorepeat = YES;
stepper.wraps = YES;
//添加点击事件 UIControlEventTouchValueChanged
[stepper addTarget:self action:@selector(changed:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:stepper];
}