0

我的滑块电流是 50。如果我向右滚动。我想得到 -0 到 - 50。如果向右滚动,我想得到 0 到 50。我不需要 1 到 100。

帮助。

- (IBAction)sliderValueChanged:(UISlider *)sender {

    if ([myLabel.text length] > 50){
      // Make - 0 to -50 
      myLabel.text =  [NSString stringWithFormat:@"%d", -(int)sender.value];
    }else  if ([myLabel.text length] < 50){   
      // Make 0 to 50
      myLabel.text =  [NSString stringWithFormat:@"%d", (int)sender.value];
    }else{
      myLabel.text =  [NSString stringWithFormat:@"%d", (int)sender.value];

    }
}
4

1 回答 1

0

设置滑块最小值最大值:

        slider.maximumValue = 100;
        slider.minimumValue = 0;
        slider.value = 50;

行动

- (void)sliderMoved:(id)sender  {
        //DLog(@"slider moved");
        UISlider*timeSlider = (UISlider*)sender;
        if (timeSlider.value < 0)   {
            timeSlider.value = -50;
        }
        else if (timeSlider.value < 30) {
            timeSlider.value = -30;
        }
        else if (timeSlider.value < 50) {
            timeSlider.value = 0;
        }
        else if (timeSlider.value < 80) {
            timeSlider.value = 30;
        }
        else if (timeSlider.value < 100)    {
            timeSlider.value = 50;
        }

        else    {
            timeSlider.value = 0;
        }
        _chosenDuration = timeSlider.value;
        [_timeLabel setText:[NSString stringWithFormat: NSLocalizedString(@"time%@", nil) , _chosenDuration]];
    }

设置所有条件你想要什么......

于 2013-04-03T10:08:54.997 回答