1、UIStepper 的创建
UIStepper *stepper = [[UIStepper alloc] init];
[self.view addSubview:stepper];
2、UIStepper 的设置
// 设置 frame
/*
大小由系统确定
*/
stepper.frame = CGRectMake(10, 30, 0, 0);
// 设置位置
stepper.center = self.view.center;
// 设置最大和最小值
stepper.minimumValue = 0;
stepper.maximumValue = 100;
// 设置当前值
stepper.value = 30;
// 获取当前值
double value = stepper.value;
// 设置一步的大小
stepper.stepValue = 5;
// 设置背景颜色
stepper.backgroundColor = [UIColor grayColor];
// 标题及边框颜色
stepper.tintColor = [UIColor redColor];
// 设置背景图片
[stepper setBackgroundImage:[UIImage imageNamed:@"pic2"] forState:UIControlStateNormal];
[stepper setBackgroundImage:[UIImage imageNamed:@"pic1"] forState:UIControlStateHighlighted];
// 设置加减号图标
// 设置加号图标
[stepper setIncrementImage:[[UIImage imageNamed:@"volum+"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
// 设置减号图标
[stepper setDecrementImage:[[UIImage imageNamed:@"volum-"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
// 设置中间分割线图标
[stepper setDividerImage:[UIImage imageNamed:@"divid"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal];
// 设置按住不放是否连续更改值
stepper.continuous = YES;
// 设置是否循环
/*
到最大值时再增加数值从最小值开始,到最小值时再减小数值从最大值开始
*/
stepper.wraps = YES;
// 添加点击触发事件
[stepper addTarget:self action:@selector(stepperClick:) forControlEvents:UIControlEventValueChanged];