views:

35

answers:

1
[sld1 setThumbImage:[UIImage imageNamed:@"Blue.png"] forState:UIControlStateHighlighted];
[sld1 setThumbImage:[UIImage imageNamed:@"Blue.png"] forState:UIControlStateNormal     ];

Would that cause the slider-bar image to disappear? Mine are all gone. (The thumb-image displays just fine.)

Apple's docs make it sounds like I can use any ONE of above 2 lines of code. (But I guess I really need both.)

And I can't find anything about "you must always do all 4":

Set the normal-state image.
Set the highlighted-state image.
Set the setMinimumTrackImage.
Set the setMaximumTrackImage.
+1  A: 

Hello :)

If you start out customizing the UISlider with graphics, you must set at least 3 pieces of graphics. Right and left side of the trackbar and the thumb image:

Here is how I did it the last time I used the UISlider:

    CGRect frame = CGRectMake(20.0f, 6.0, 280.0f, 20.0f);
    UISlider *customSlider = [[UISlider alloc] initWithFrame:frame];
    [customSlider addTarget:self action:@selector(sliderMove:) forControlEvents:UIControlEventValueChanged];
    [customSlider addTarget:self action:@selector(sliderStart:) forControlEvents:UIControlEventTouchDown];
    [customSlider addTarget:self action:@selector(sliderEnd:) forControlEvents:UIControlEventTouchUpInside];        
    [customSlider addTarget:self action:@selector(sliderEnd:) forControlEvents:UIControlEventTouchUpOutside];   

    // in case the parent view draws with a custom color or gradient, use a transparent color
    customSlider.backgroundColor = [UIColor clearColor];    
    UIImage *stetchLeftTrack = [[UIImage imageNamed:@"slider.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

     UIImage *stetchRightTrack = [[UIImage imageNamed:@"slider_right.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

    [customSlider setThumbImage: [UIImage imageNamed:@"slider-knop.png"] forState:UIControlStateNormal];
    [customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
    [customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];

I my optics it does not make sense to have a highlighted state for the UISlider, or any other state, your finger will likely cover the thumb image, so the user will never see it. I am not sure it just extends from UIButton and maybe it can't handle it?

RickiG
"Must modify at least 3 images": Seems like that works differently if you make your slider with IB or Code. (How am I going to keep all this straight???)
Susanna
"No sense in changing the highlighted state": I *NEVER* keep my thumb over the thumbImage when I slide it. No need to. It still works. So I never want my image to abruptly change back to some other graphic because I forgot to set the highligted state.
Susanna
Where do you get your "slider_right and left png" images? Is there a way to find/load/use the images already built into the frameworks? (In the unlikely event that Apple changes them in the future.) Or do I have to go and screen-capture the existing ones... just to save them... and include them in my bundle... and reload them? (Ugh, what a waste of time.)
Susanna
1. I don't know about IB, but if I try to set only the right track, the left will not use the default, it is just empty.2. The only case I know of, is the timeline in the iPod app, other sliders you can't move unless being on the thumb image (is controlled in the different UIControllEvents I set. i.e. have it respond to dragOutside.3. If you don't customize at all it will default to Apples design. The images I refer to I drew myself. (It is a green slider with a square thumb) Just draw it 36x9 or something(for the right and left track) and the slider will scale it up as you slide.
RickiG