1

Having a UISLider with min value 5 and max value 10 how can I show the value range with 0.5 interval in uilabel

_ie.text = [NSString stringWithFormat:@"%0.1f",(_Iel.value)];
Jaswanth Kumar
  • 158
  • 1
  • 9
  • 1
    Use "steps", like this one: http://stackoverflow.com/questions/2519460/uislider-with-increments-of-5 just adapt it to your needs. – Larme Oct 01 '15 at 07:58

2 Answers2

3

You can round like this:

_ie.text = [NSString stringWithFormat:@"%0.1f",(roundf(_Iel.value * 2.0) * 0.5)];
tuledev
  • 10,177
  • 4
  • 29
  • 49
0

This will work for 0.5 or any other interval

- (IBAction)sliderValueChanged:(id)sender
{
    self.increment = 0.5f;
    float roundedSliderValue = roundf(self.theSlider.value / self.increment) * self.increment;
    _ie.text = [NSString stringWithFormat:@"%0.1f",roundedSliderValue];
}
Ahmed Hamed
  • 504
  • 1
  • 3
  • 11