UISlider snapping

Discussion in 'iOS Programming' started by Duke Leto, Jan 27, 2009.

  1. Duke Leto macrumors regular

    Joined:
    Mar 17, 2008
    #1
    Is it possible to set a UISlider to "snap" to certain values other than by checking if the value selected is near and setting the value to that?
    I am capable of the code, but I do not want to waste time.
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    Not to my knowledge. Class ref is here, I guess you could hack thumbRectForBounds to make it look like it's snapping to discrete values, though it's a nasty kludge...
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    UISlider can effectively snap by putting the right logic into the sliderChanged: method. Here's the code I used to achieve a gender (i.e. Male / Female slider):
    Code:
    		if (slider.value >= 0.5) {
    			slider.value = 1.0;
    			genderCode = @"F";
    		} else {
    			slider.value = 0.0;
    			genderCode = @"M";
    		}
    
     

Share This Page