iOS 6.1 XCode 4.6 - imageNamed never return @2x version

290 Views Asked by At

Both files "flipImage.png" and "[email protected]" are in project. In -[FlipsideViewController viewDidLoad] I have the following code. The sanity check (thanks to other stackoverflowers) correctly reports retina or no. But in either case, the image loaded is the small one, verified by its height. Why no auto-load of appropriate image? OK, I can see workarounds, but I'd like to Use The System when possible.

UIImage* flipimage = [UIImage imageNamed:@"flipImage.png"];
NSLog(@"Image height = %f", flipimage.size.height);  // always 416, never 832 :(

// Sanity check.
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
    NSLog(@"Retina");
} else {
    NSLog(@"Non-retina");
}   
2

There are 2 best solutions below

3
On

iOS retina displays don't work that way. The height of an @2x image and a standard resolution image will be the same on the device and in your code. When you create an image on the screen that is 416 points x 416 points, it doesn't change height just because it's on a retina display versus a non-retina display.

The difference is that @2x images have higher resolutions so they show more pixels per point which is what the retina displays are using instead of pixels.

So essentially, all you need to do is use the standard resolution filename for any image you use within the app and the OS will automatically take care of replacing it with the higher resolution images if it's on a retina display.

0
On

According to the previous comments... and without having to change your code a lot, why don't you just do this:

UIImage* flipimage = [UIImage imageNamed:@"flipImage.png"];
NSLog(@"Image height = %f", flipimage.size.height * [UIScreen mainScreen].scale);

That should returned you the size (Number of points * number of pixels per point).