Archive for September 2012 | Monthly archive page
Supporting Tall Retina Images in iPhone apps
If you have an iPhone app or are developing one, with the launch of iPhone5 , you need to ensure that your images scale to support the new taller retina display (640X1136).
In case of the launch image, naming the new launch with the suffix "-568h@2x" (e.g.. Default-568h@2x) will ensure that the system picks up the right launch image for the iPhone5.
However, just adding the "-568h@2x" to the new images is not sufficient to have the system pick the right images for the tall retina display. Here is a very simple category on UIImage that can be used to return the right image. Note that in the category implementation, I assume that all the iPhone5 specific images are named with a suffix of "-568h@2x".
The "UIImage+iPhone5extension.h" Interface definition
#import <UIKit/UIKit.h>@interface UIImage (iPhone5extension)+ (UIImage*)imageNamedForDevice:(NSString*)name;@end
The "UIImage+iPhone5extension.m" file implementation
#import "UIImage+iPhone5extension.h"@implementation UIImage (iPhone5extension)+ (UIImage*)imageNamedForDevice:(NSString*)name {UIImage *returnImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@", name]];if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){if (([UIScreenmainScreen].bounds.size.height * [UIScreenmainScreen].scale) >=1136){return [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h@2x", name]];}}return returnImage;}@end
Just include the above files in your project and replace relevant occurrences of [UIImage imageNamed:] call with [UIImage imageNamedForDevice:]. This would ensure that right image is picked up for non-retina,retina and tall retina versions of the resolution.