tags:

views:

1200

answers:

2

Hi,

I need to add an UISlider control in my iphone application. That should look like the "Slide to unlock" slider which is displayed in any iphone or ipod touch. I am unable to figure out how to do this.

In slide to unlock slider, if we leave the thumbImage in the middle of the slider it comes back to the left side automatically. How do we get this kind of functionality working in our project.

+1  A: 

The "Slide to Unlock" appears to closer to UISwitch than UISlider.

Customizing UISwitch is undocumented.

If you are comfortable using undocumented features check out Developers's Cookbook by Erica Sadun - chapter 8.

The sample code for this chapter can be found at http://code.google.com/p/cookbooksamples/downloads/list.

thanks for your answer
saikamesh
+4  A: 

You have to implement this yourself using the UISlider methods. First you have to create a slider of the proper size in code using initWithFrame:. Then just chop up the images that you'd like and set them using:

setMinimumValueImage:(UIImage*)image;
setMaximumValueImage:(UIImage*)image;
setThumbImage:(UIImage*)image forState:(UIControlState)state;
setMinimumTrackImage:(UIImage*)image forState:(UIControlState)state;
setMaximumTrackImage:(UIImage*)image forState:(UIControlState)state;

Then, in your slider's action method, check to see if the slider is at the maximum value. If not, use

setValue:(float)val animated:(BOOL)flag

most likely using animated=YES. I think you have to turn off continuous updates or you will get actions at every step, causing you to always animate backwards. You may have to tweak some of this but it should work well. You aren't going to get the text effect that Apple does but using static images it will get pretty close.

Steven Canfield
Thanks a lot. Actually before looking at your answer I myself tried what you said. It worked well. Thanks once again!!!
saikamesh