·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> UIStepper

UIStepper

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

//初始化stpper,大小是固定的
    UIStepper *step=[[UIStepper alloc]initWithFrame:CGRectMake(100, 100, 0, 0)];
    //设置最小值最大值
    step.minimumValue=1;
    step.maximumValue=30;
    //设置每次增加的值
    step.stepValue=1;
    //设置允许循环
    [step setWraps:YES];
    //设置初始值
    step.value=2;
    //添加点击事件,让数值显示在界面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];
}