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...
Any help will be appriciated.
Here is simple Example of
UISlider
headereFile.h
implementFile.m
I use this bit of code when I want the increment to be 0.5. It works with 1 or any other number
change
to
if you want one digit then :
but this will give you results like 1.0,1.1,....
also see this bellow answer helpful toy you,give some idea...
UISlider increments
and also another which may give you some idea..
UISlider with increments of 5
I know i'm late to the party but I've also had to do this recently. Here is how I've done it in swift using XCode 8.3.2:
Simples! I know I could have used 'Any' instead of 'UISlider', but I think this makes my intention clearer ;)