简体   繁体   中英

Custom UISlider Image disappearing?

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

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

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

In Swift -

customSlider.setThumbImage(#imageLiteral(resourceName: "slider_icon"), for: .normal)
customSlider.setThumbImage(#imageLiteral(resourceName: "slider_icon"), for: .highlighted)

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