Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change iPhone UISlider bar image

I'm using a UISlider in my app but I'd like to use a custom "look-and-feel" for it. I have changed the thumb to my own image but is there a way to change the bar also? I have a bar image I would like to use but can't see how to do this.

I have found how to change the max and min image but not the bar itself.

like image 393
Fogmeister Avatar asked Mar 04 '10 12:03

Fogmeister


1 Answers

You were right to use -setMinimumTrackImage:forState: and -setMaximumTrackImage:forState: methods. What you missed is that you should provide stretchable UIImage to them, the rest is taken care of automagically:

UIImage *sliderLeftTrackImage = [[UIImage imageNamed: @"SliderMin.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0]; UIImage *sliderRightTrackImage = [[UIImage imageNamed: @"SliderMax.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0]; [mySlider setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal]; [mySlider setMaximumTrackImage: sliderRightTrackImage forState: UIControlStateNormal]; 

You can use the same image for both the min and max parts.

like image 60
Costique Avatar answered Sep 18 '22 22:09

Costique