IOS - custom image for UISlider

I want to use an image for the UISlider track. I do not need one color to the left of the thumb, and another color to the right. I just want one static image all over the track. Is it possible?

+7
source share
3 answers

To set the image on the slider, you can use the setMinimumTrackImage , setMaximumTrackImage methods . For your requirement, set both of the same images.

iOS 5 and below

UIImage *sliderTrackImage = [[UIImage imageNamed: @"Slider.png"] stretchableImageWithLeftCapWidth: 7 topCapHeight: 0]; [mySlider setMinimumTrackImage: sliderTrackImage forState: UIControlStateNormal]; [mySlider setMaximumTrackImage: sliderTrackImage forState: UIControlStateNormal]; 

iOS 5+

 UIImage *sliderTrackImage = [[UIImage imageNamed:@"Slider.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 7, 0, 0)]; [mySlider setMinimumTrackImage: sliderTrackImage forState: UIControlStateNormal]; [mySlider setMaximumTrackImage: sliderTrackImage forState: UIControlStateNormal]; 

For more details see the following links:

+16
source
 [[UISlider appearance] setThumbImage:[UIImage imageNamed:@"ball.png"] forState:UIControlStateNormal]; [slider setMinimumTrackImage:[[UIImage imageNamed:@"volume_slider_oragne.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal]; [slider setMaximumTrackImage:[[UIImage imageNamed:@"volume_strap_gry.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal]; 
+4
source

Just set both sides to the same image. You might want to make two separate images with the same color / pattern if you want rounded corners at the ends.

0
source

All Articles