I am new to iPhone,
How do I have my UISlider go from 1 to 100 in increments of 1
?
slider = [[UISlider alloc] init];
[slider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
[slider setBackgroundColor:[UIColor clearColor]];
slider.minimumValue = 1;
slider.maximumValue = 100;
slider.continuous = YES;
slider.value = 0.0;
- (IBAction)sliderChange:(id)sender{
NSLog(@"slider.value=%f",slider.value);
}
When i slide my log shows...
slider.value = 1.000000
slider.value = 1.123440
slider.value = 1.234550
slider.value = 1.345670
slider.value = 1.567890
.
.
.
I want slider value as 1.0 , 2.0 , 3.0 and so on...
//Only generate update events on release
slider.continuous = NO;
//Round the value and set the slider
- (IBAction)sliderChange:(id)sender
{
int rounded = sender.value; //Casting to an int will truncate, round down
[sender setValue:rounded animated:NO];
NSLog(@"%f", sender.value);
}
you could try this:
float RoundValue(UISlider * slider) {
return roundf(slider.value * 2.0) * 1;
}
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