If you were previously loading a UIImage with initWithContentsOfFile, you will need to change your code slightly if you want to support the high resolution capabilities of the iPhone 4 retina display. For some reason you must now load an image with imageNamed if you want iOS 4 on an iPhone 4 to auto select the high res image with the @2x file extension.
I have contacted Apple regarding this issue and have yet to hear back from them. I will let you all know what they say.
Previously you could have done the following:
NSString *imgPath = [[NSBundle mainBundle] pathForResource:@"image.png"]; UIImage *image = [[UIImage alloc] initWithContentsOfFile: imgPath];
You must change your code like this:
UIImage *image = [UIImage imageNamed:@"image.png"];
NOTE: If you want your app to also work on iPhone OS 3 you must include the image extension such as ‘.png’ but you are no longer required to do so with iOS 4 only apps.
Random Posts:
- iOS 4.1 seeded to developers
- iStrobe Open Sourced Publicly
- D/L Stats for SpaceBubble
- SpaceBubble 1,000 downloads / day
- Source Code to iStrobe
If you found this useful, shoot me a small donation or at the very least leave a comment, every bit of encouragement helps keep me motivated to update with more content on a regular basis!
Tags: Development, display, ios, iPhone, iphone 4, Objective-C, programming, retina, uiimage, Xcode
You can skip to the end and leave a response. Pinging is currently not allowed.
[...] to support the retina display on the iPhone 4. It was quite simple really, just had to change a few lines of code, edit my Entitlements.plist file, and add high resolution [...]
The new way is much simpler though. Good move, but did they have to break initWithContentsOfFile? Why not just deprecate it? :/
[...] other day I posted about a problem with using initWithContentsOfFile to load a high res image on the iPhone 4. At the same time I submitted a bug report to Apple. Today [...]
Interesting bug.
But if the other method (image named) was an option before why wasn’t it the common practice before as it’s so much simpler?
So that means you have to include image.png(normal res) and image@2x.png(high res) on your project?
Not clear for me, sorry.
Yes.
imageNamed: is bad for me because it caches the images in memory (and there is no way to clear out the cache myself). What if I don’t want to cache my images?
What if your image is not in the main bundle? This doesn’t seem to work when pulling an image from the documents folder.