Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISlider track image that doesn't stretch

I'm trying to use a custom track image for a UISlider but it is an asymmetric image from one end of the slider to the other.

I have tried setting up my image with leftCapWidth and so on but this just makes it take a maximum stretch and then starts spreading out one pixel of infor across the slider.

I'd like an image that doesn't change at all when you move the slider.

Is this at all possible?

like image 218
Fogmeister Avatar asked Oct 14 '22 08:10

Fogmeister


1 Answers

You can use this to make the background of the UIslider custom ,make the UIslider as an IBoutlet

[yourslider setThumbImage:[UIImage imageNamed:@"icon0.png"] forState:UIControlStateNormal];



yourslider.minimumValue=1;
yourslider.maximumValue=10;

UIImage *sliderLeftTrackImage = [[UIImage imageNamed: @"yellow_bg.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];
UIImage *sliderRightTrackImage = [[UIImage imageNamed: @"yellow_bg.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];

[yourslider setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal];
[yourslider setMaximumTrackImage: sliderRightTrackImage forState: UIControlStateNormal];
like image 184
hacker Avatar answered Oct 17 '22 00:10

hacker