Kuldeep Singh
Kuldeep Singh

Reputation: 336

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.without retina image But the problem is When i add retina image([email protected] 106 X 398), the thumb image becomes very wider and longer than the simple image.with retina

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:@"[email protected]"];

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

Upvotes: 0

Views: 1321

Answers (2)

Deepak Srivastava
Deepak Srivastava

Reputation: 170

No need to add @2x just use this like :

[self.slider setThumbImage:[UIImage imageNamed:@"n.png"] forState:UIControlStateNormal];

Upvotes: 2

Razvan
Razvan

Reputation: 4122

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.

Upvotes: 2

Related Questions