简体   繁体   中英

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?

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM