简体   繁体   中英

Thumb image in retina not working in UISlider

I am working on UISlider in which i have added a Thumb image (slider_iphone.png 53 X 199) over the slider. 没有视网膜图像 But the problem is When i add retina image(slider_iphone@2x.png 106 X 398), the thumb image becomes very wider and longer than the simple image. 视网膜

I have searched a lot over google and stack overflow but didn't find any solution. Why is it not taking the retina image in correct frame. Please suggest any solution.

Code:

slider = [[UISlider alloc]initWithFrame:CGRectMake(0.0,180.0,320.0,180.0)];

[slider setMinimumValue:1.0f];

[slider setMaximumValue:10.0f];

[slider addTarget:self action:@selector(sliderMoved:) forControlEvents:UIControlEventValueChanged];

UIImage *sliderTrackImage1 = [[UIImage imageNamed: @"button-transparent.png"] stretchableImageWithLeftCapWidth: 0.0 topCapHeight: 0.0];

UIImage *thumb = [UIImage imageNamed:@"slider_iphone@2x.png"];

[slider setMinimumTrackImage: sliderTrackImage1 forState: UIControlStateNormal];
[slider setMaximumTrackImage: sliderTrackImage1 forState: UIControlStateNormal];
[slider setThumbImage:thumb forState:UIControlStateHighlighted];
[slider setThumbImage:thumb forState:UIControlStateNormal];

You shouldn't use the @2x image defined in code!

Have both the normal image and the @2x image in your bundle and in code specify the normal image!

The app will appropriately select what image it needs depending on device's screen.

无需添加@ 2x就可以像这样使用:

[self.slider setThumbImage:[UIImage imageNamed:@"n.png"] 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