Reputation: 1532
When running app in Iphone 5, I discovered that [UIImage imageNamed]
doesn't detect retina display when it comes to iphone or ipod 5. I have 2 images for everything in my app, the standard one, and the retina one named @2x. Now, I used to select the regular image in storyboard or programmatically because I thought it would get the right image automatically, like simulator does, but turns out, Iphone 5 doesn't. So, for my understanding, I have to manually check if is retina using the code:
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
// Retina display
NSLog(@"RETINA");
} else {
// non-Retina display
NSLog(@"NON-RETINA");
}
Now, since I'll be using this code a lot, is there a way to avoid repeating it? Maybe creating a protocol, or even subclassing UIImage
? I'm not sure how to deal with this, I thought this was done automatically.
Upvotes: 0
Views: 848
Reputation: 1166
imageNamed
picks the correct image.
Please try to uninstall your app from your phone, and clean and build your project before running it again on your iphone 5.
Sometimes happens that the images are not correctly refreshed i you don't make a clean install.
Upvotes: 1
Reputation: 1107
If the simulator is seeing the retina images and your device isn't than there might be a problem with case sensitivity. The simulator doesn't care but the actual devices do. Check the names of your images with and without the @2x for differences in upper and lowercases.
If this doesn't solve your problem (which would be very strange) you can automate the method by adding this to your .m file:
-(BOOL)retinaScreenResolution {
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0))
return YES;
else
return NO;
and call it anywhere in your code with:
if ([self retinaScreenResolution]) {
//YES retina
}
else {
//NO
}
Upvotes: 1
Reputation: 4980
from apple docs of [UIImage imageNamed:]
If the screen has a scale of 2.0, this method first searches for an image file with the same filename with an @2x suffix appended to it. For example, if the file’s name is button, it first searches for button@2x. If it finds a 2x, it loads that image and sets the scale property of the returned UIImage object to 2.0. Otherwise, it loads the unmodified filename and sets the scale property to 1.0.
so your assumption is wrong according to the docs
Upvotes: 0