首页 > 解决方案 > 当 UIStepper 增加值时如何显示 UISwitch

问题描述

我想做一个关于何时单击 UIStepper 并将其递增到 1 的任务。然后应该出现一个开关,当再次单击 UIStepper 时,另一个开关应该显示在第一个开关下方。

当 UIStepper 增加时,我需要垂直显示至少 5 个开关。

-(void)onstepperClicked:(UIStepper*)selectedComponent {
if (selectedComponent == self.mainStepper) {
    if (self.mainStepper.value >=0) {
           float y=20;
        //output label
        self.outputLabel.text = [NSString stringWithFormat:@"%d",(int)self.mainStepper.value ];
        // slider animated with stepper
        [self.mainSlider setValue:self.mainStepper.value animated:YES];
        //switch
        self.repeatingSwitch = [[UISwitch alloc]init];
        self.repeatingSwitch.frame=CGRectMake(20,y+50,100, 100);
        [self.view addSubview:self.repeatingSwitch];
        self.repeatingSwitch.tintColor=[UIColor redColor];
        self.repeatingSwitch.onTintColor=[UIColor greenColor];
        self.repeatingSwitch.thumbTintColor =[UIColor blackColor];
    }


    }
}

标签: iosobjective-cuiswitchuistepper

解决方案


在笔尖中设计一个自定义单元格,UISwitch里面只有一个。然后在您设计的称重传感器UITableView下方设置一个。UIStepper

当您单击时,UIStepper只需增加UITableViewDataSource方法中的行数。


推荐阅读