步进 控件主要应用还是在购物App的购物车商品加减的地方,所以一般属性,就是最大最小值,每次增减的值,还有就是是不是值是不是在最大或者最小值之间循环。
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.stepper = [[UIStepperalloc]initWithFrame:CGRectMake(10,50, 50, 50)];
self.label = [[UILabelalloc]initWithFrame:CGRectMake(0,150, 200, 20)];
[self.labelsetText:@"当前的值:(0)"];
[self.steppersetBackgroundColor:[UIColorredColor]];
[self.viewaddSubview:self.label];
[self.viewaddSubview:self.stepper];
//最大值
self.stepper.maximumValue=100;
//最小值
self.stepper.minimumValue=0;
//每次的增量
[self.steppersetStepValue:1];
//默认值
self.stepper.value=0;
//控制是否持续触发UIControlEventValueChange事件.设置为NO则松开按钮时候触发
self.stepper.continuous=YES;
[self.stepperaddTarget:selfaction:@selector(changeValue:)forControlEvents:UIControlEventValueChanged];
//控制是否按住的时候自动增减自动增减与持续触发UIControlEventValueChange没什么必然关系,不持续触发UIControlEventValueChange事件,但是控件按住是自动增长的当松开时候,UIControlEventValueChange所在的方法会得到一个计算后的值
self.stepper.autorepeat=YES;
//是不是在最大值还有最小值之间循环
self.stepper.wraps=YES;
}
-(void)changeValue:(id)sender{
NSLog(@"当前的值:(%f)",self.stepper.value);
self.label.text = [NSStringstringWithFormat:@"当前的值:(%.0f)",self.stepper.value];
}
新闻热点
疑难解答