To increase the slider value by 10

I have a slider. The minimum value for this parameter is 0 s and the maximum value is 3 minutes (or 180 seconds). I want to increase the value of the slider by 10 seconds. How can I get it? Please, help.


source to share

3 answers

Assuming the slider will increase / decrease in 10 steps ...

Connect the slider value changed in IB (or UIControlEventValueChanged

in code) to a method in your view controller, for example:

- (IBAction)sliderValueChanged:(id)sender {
    int value = (int)[self.slider value];   
    int stepSize = 10;
    value = (value - value % stepSize);
    // Set the new value.
    self.sliderValue = value; 



is a separate integer property to keep track of the value (instead of changing the base value of the slider causing UI issues)



[mySlider setValue:([mySlider value]+10) animated:YES];


Turn "animated" to "NO" if you don't want your slider to animate the new value.



If you only want the slider to increase by only 10, move the slider from 0 to 18, and whenever you use or display a value, multiply it by 10.



All Articles