Add a goal like this:
slider.continuous = YES; [slider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
And in the valueChanged function, set the value to the nearest value, which is divided by 5.
[slider setValue:((int)((slider.value + 2.5) / 5) * 5) animated:NO]
Therefore, if you need an interval other than 5, just set it like this:
float interval = 5.0f;//set this [slider setValue:interval*floorf((slider.value/interval)+0.5f) animated:NO];
Tuomas Pelkonen Mar 25 '10 at 21:32 2010-03-25 21:32
source share