Search code examples
xcodexcode4.2resolutionretina-displayimagenamed

Retina support imageNamed @2x not working


Possible Duplicate:
iOS 5.1 with Xcode 4.2 and retina in iPad 3

I am trying to make my app load on iPad 2 (since its running great on iPad 3). I have downscaled the images and now have 2 sets of images like: image.png and [email protected]. When I try to load the image with:

someImageView.image = [UIImage imageNamed:@"image.png"];

Or through the IB, it does not give me the result I expected (like choosing the correct version of the image depending on the iPad's display as stated here) and only displays the image.png no matter which iPad runs the application, though when I try to import the image through:

NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
UIImage* someImage = [[UIImage alloc] initWithContentsOfFile:imagePath];
someImageView.image = someImage;

This works just fine and when I run the app on iPad 3 it uses the @2x png file. Although this works, I am not sure I have to allocate and release every single image I use, since I use some images through IB. Is that a normal behaviour?

I used SDK 4, 4.2 and 5 but nothing changed, also I am using Xcode 4.2, since I dont want to switch to Lion.

  • I have tried not using someImageView.image = [UIImage imageNamed:@"image.png"]; and just pick the image "image.png" in the IB slot. Didn't work.
  • I tried with just typing image in the IB slot. Didn't work. It picks up image.png no matter what.
  • I tried using someImageView.image = [UIImage imageNamed:@"[email protected]"]; It shows the 2x image in any device.
  • I tried using image@2x~ipad.png and image~ipad.png . Didn't work.
  • All sets of images are named correct, size is correct and have all been imported to the project in the same group/folder.
  • It is not a universal, but an iPad application.
  • I have cleaned the build several times during the process.

Any help is greatly appreciated!

*UPDATE: UIImage switches to @2x when [UIScreen mainScreen].scale is returning 2. When I check that, it returns 1, which is the reason @2x is not activated. So does anyone know if 4.2 does not recognize iPad3 retina display? I found something similar here.

*UPDATE 2: I managed to get this working by merging SDK 5.1 into the Xcode and using it as base SDK. It didn't work when I had both SDK 5 and 5.1 in the SDKs folder, worked as a charm when I removed the SDK 5 version.


Solution

  • It's not working by default, because Xcode 4.3.1 was the first version to support the new iPad (retina)

    If you want to get it working anyways, check this answer