I need to set the interval value for an UISlider.
Please help..
yourSlider.value = x;
You should really read the documentation, lots of great resources in the iOS Developer Center.
Edit: With regards to your more specific question in the comments:
yourSlider.minimumValue = -10;
yourSlider.maximumValue = 10;
[yourSlider addTarget:self action:@selector(roundValue) forControlEvents:UIControlEventValueChanged];
- (void)roundValue{
yourSlider.value = round(yourSlider.value);
}
A flexible solution:
// define MIN_VALUE, MAX_VALUE and INTERVAL somewhere, such as 3, 18 and 3
slider.TouchUpInside += delegate {
touchUpInside();
};
/// <summary>
/// set value to one of intervals
/// </summary>
void touchUpInside(){
// get the nearest interval value
for(int i=MIN_VALUE; i<=MAX_VALUE; i=i+INVERVAL){
if(slider.Value > i && slider.Value < i + INVERVAL){
if(slider.Value - i < i + INVERVAL - slider.Value){
slider.Value = i;
}else{
slider.Value = i + INVERVAL;
}
break;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With