Monday, February 21, 2011

How to UISlider with increments of 5

How do have my UISlider go from 1-100 by going by 5s?

From stackoverflow
  • Add a delegate like this:

    slider.continuous = YES;
    [slider addTarget:self
          action:@selector(valueChanged:) 
          forControlEvents:UIControlEventValueChanged];
    

    And in the valueChanged function set the value to the closest value that is divisible by 5.

    [slider setValue:((int)((slider.value + 2.5) / 5) * 5) animated:NO];
    
    Tyler29294 : Thanks works like a charm!
    Tuomas Pelkonen : Good. If it works like a charm, you could consider accepting my answer.

0 comments:

Post a Comment