You’ll be familiar with the way that [UIImage imageNamed:] automatically loads @2x versions of images when running on a retina device.
Unfortunately, imageNamed: will NOT automatically load -586h@2x versions of images when running on an iPhone 5.
Sometimes this doesn’t matter, for example icons and non-full screen graphics are probably the same on iPhone 4 & 5. However, if you have full-screen background images, or full-width / height background images for toolbars etc you will have problems. Your 480-high images will most likely get stretched (and will probably look horrid as a result).
There is a better way to load automatically -586@2x versions of images(if available) than manually checking the screen size.
Here is a category named Retina4 of UIImage to do exactly this thing.
https://gist.github.com/3784303.js?file=UIImageRetina4.h
https://gist.github.com/3784303.js?file=UIImageRetina4.m
This code is originally made by Benjamin Stahlhood though I fixed below problems that are existed in original version.
- Replacing imageNamed: method for retina4 is executed multiple times. So retina4ImageNamed: is never called in some cases.
- The scale property of UIImage is set to 1.0f instead of 2.0f because the filename is specified with “@2x”.
Hi Dear,
Does ‘method_exchangeImplementations’method reject by apple while submitting application in apple store?
Please review “http://stackoverflow.com/questions/7720947/method-swizzling-in-ios-5” and let me know.
Thanks in advance.
Regards,
PS
いいねいいね
@Poojan
Hi, I’m using this code in my app but I haven’t ever been rejected from apple.
Cheers,
nora
いいねいいね