Search code examples
iphoneobjective-ccocoa-touchxcode4uislider

Changing Default Behaviour of UISlider - No continuous sliding and Custom button


enter image description here

I want to achieve above type of UI using slider... But Slider should stop at only 3 positions 1. Extreme Right 2. Extreme Left 3. Center

Will it be possible to achieve this type of UI using UISlider in iPhone?? How should I achieve it??

EDIT:

I want to achieve same as TrackBar in VB.NET. Is it possible with the UISlider??? or please suggest me some other control/code in iPhone apart from SegmentedControl...

EDIT 2

int progressAsInt =(int)(slider.value + 0.5f);
NSString *newText =[[NSString alloc] initWithFormat:@"%d",progressAsInt];
sliderLabel.text = newText;

Solution

  • Look at the documentation for UISlider. The methods you are interested in are setMinimumTrackImage: forState: and setMaximumTrackImage: forState: to set the track, setThumbImage: forState: for the slider thumb

    To make it stick at the beginning, middle or end, your viewcontroller should, in the valueChanged method linked to from the slider, determine the appropriate value and then use setValue: animated: to move the slider to the appropriate place. So, if your slider goes from 0 to 2, and the user changes it to 0.75, you assume this should be 1 and set the slider value to that.

    Also - turn off the continuous property or the above won't work.