Search code examples
iphoneuislider

To increment slider value by 10


I have a slider. Minimum value of this is 0sec and maximum value is 3min(or 180 sec). I want to increment the slider value by 10 sec. How can I get this? Please help.


Solution

  • Assuming you want the slider to increment up/down in steps of 10...

    Hook up the slider's value changed event in IB (or UIControlEventValueChanged in code) to a method in your view controller such as:

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

    The self.sliderValue is a separate integer property to track the value (rather than changing the underlying value of the slider causing UI issues)