//初始化stpper,大小是固定的
UIStepper *step=[[UIStepper alloc]initWithFrame:CGRectMake(100, 100, 0, 0)];
//設(shè)置最小值最大值
step.minimumValue=1;
step.maximumValue=30;
//設(shè)置每次增加的值
step.stepValue=1;
//設(shè)置允許循環(huán)
[step setWraps:YES];
//設(shè)置初始值
step.value=2;
//添加點擊事件,讓數(shù)值顯示在界面label中
[step addTarget:self action:@selector(putValueOut:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:step];
//點擊事件
-(void)putValueOut:(UIStepper *)stepper
{
int a=stepper.value;
_label.text=[NSString stringWithFormat:@"%d",a];
}
新聞熱點
疑難解答