views:

185

answers:

2

Hello all i have a custom image to replace the UISLider defult button image, all works fine image shows, it does not clip off. The problem is when i use the slider to move up and down the image dissapears and some how doesnt show up anymore only sometimes. could someone have a fix?

CGRect rect = CGRectMake(16.0, 390.0, 297.0, 35.0);
slider.frame = rect;

UIImage* thumbImage = [UIImage imageNamed:@"thumb.png"];   
[slider setThumbImage:thumbImage forState:UIControlStateNormal];

UIImage* leftImage = [UIImage imageNamed:@"SliderLeft.png"];   
[slider setMinimumTrackImage:leftImage forState:UIControlStateNormal];   

UIImage* rightImage = [UIImage imageNamed:@"SliderRight.png"];
[slider setMaximumTrackImage:rightImage forState:UIControlStateNormal];
A: 

I'd bet the setThumbImage method, and the other methods, do not retain the image passed to them, so you'll need to retain the UIImage you are getting back from the imageNamed method. Either create properties for thumbImage, leftImage, and rightImage, or add the retain call after you get the image. There's an example project that supports this idea, so I assume that's how it should be done.

UIImage* thumbImage = [[UIImage imageNamed:@"thumb.png"] retain];
Ken Pespisa
+1  A: 

I believe you need to set the highlighted state image as well:

[slider setThumbImage:thumb forState:UIControlStateNormal];     
[slider setThumbImage:thumb forState:UIControlStateHighlighted];
micahp