views:

714

answers:

2

I want to set the thumb image of a slider for a normal state, but still use the default track images.

So i do this:

[theSlider setThumbImage:[UIImage imageNamed:@"my_thumb.png"] 
forState: UIControlStateNormal];

and I get my image appear as thumb, but then default track images disappear.

Can't you just customize the thumb image and leave the track images default?

+2  A: 

It doesn't seem like this is possible, strangely.

As a workaround, you have a couple choices. It shouldn't be too difficult to screenshot and extract the necessary graphics to create your own nearly-identical min and max track images. You'll need to get the rounded edges and a couple pixels of the flat part which will be stretched.

Alternately, you could try to extract the actual images using this technique: Extract UIKit artwork

Personally, I don't see why you can't mix and match custom graphics with default graphics, but this seems to be how Apple implemented this control.

pix0r
@pix0r thanks for the link, I'll give that a try. Apple's SDK is full of surprises, isn't it :) i didn't see anything in the docs saying that if you customize one image you have to do all. I will be submitting a bug to apple
subjective-c
A: 

Longtime Stack user, first time contributing! :)

I was experiencing the same problem and have found a workaround.

When you are creating your UISlider, whether it be in Interface Builder or progmatically be sure to set the Continuous variable to YES. (ie. [mySlider setContinuous:YES]). After this variable is set, you should be able to use your own thumb images.

IllyaB
Thanks for posting this. I finally got a chance to try your workaround, but for some reason it's not doing it for me. Are you doing anything else?
subjective-c
I just tried the workaround again myself, and it doesn't work anymore, very weird! To fix this problem, I deleted the slider I was using in IB and added another, attaching the old reference to the new slider. This worked, hopefully it will work for you if you still need it. :)
IllyaB