How to use UIStepper

后端 未结 5 404
無奈伤痛
無奈伤痛 2020-12-13 09:06

I am trying to work with UIStepper to increment or decrement an integer, but both \"-\" and \"+\" increase the integer! How can I recognize the \"+\" and \"-\

5条回答
  •  误落风尘
    2020-12-13 09:50

    Take the outlet of UIStepper:

    @property (strong, nonatomic) IBOutlet UIStepper *stepper;
    

    In viewDidLoad Method:

    self.stepper.wraps=YES;
    

    if YES, value wraps from min <-> max. default = NO

     self.stepper.autorepeat=YES;
    

    if YES, press & hold repeatedly alters value. default = YES

    Set the initial value to 0.

    NSUInteger value= self.stepper.value;
    
    self.label.text= [NSString stringWithFormat:@"%02lu",(unsigned long)value];
    

    Set the Maximum value

    self.stepper.maximumValue=50;
    

    Take the action of UIStepper:

    - (IBAction)valueDidChanged:(UIStepper *)sender {
    //Whenever the stepper value increase and decrease the sender.value fetch the curent value of stepper
            NSUInteger value= sender.value;
            self.label.text= [NSString stringWithFormat:@"%02lu",value];
    }
    

提交回复
热议问题