Xcode 6 how to set separate @2x images for iPhone 5 and 6 devices? Xcode 6 how to set separate @2x images for iPhone 5 and 6 devices? ios ios

Xcode 6 how to set separate @2x images for iPhone 5 and 6 devices?


set your image name like this;

image-320@2x//iPhone 5

image-375@2x//iPhone 6

NSNumber *screenWidth = @([UIScreen mainScreen].bounds.size.width);NSString *imageName = [NSString stringWithFormat:@"image-%@", screenWidth];UIImage *image = [UIImage imageNamed:imageName];


Images.xcassets has option to provide separate image for iPhone 5(Retina 4 @2x), iPhone 6(@2x) and iPhone 6 plus(3x).

enter image description here

There is no option for iPhone 4 asset(probably apple is stopping iPhone 4 support) rather it takes @2x images (scale mode) for iPhone 4 also but you can do something like This post for iPhone 4

Update Xcode 7

There is no option for separate image with Images.xcassets now in Xcode 7, We have to use same 2x images for all Retina devices and 3x for Retina HD device


If you want to explicitly do different stuff on different devices, you need to do it in code for now, like Valar Morghulis said.

NSNumber *screenWidth = @([UIScreen mainScreen].bounds.size.width);NSString *imageName = [NSString stringWithFormat:@"image-%@", screenWidth];UIImage *image = [UIImage imageNamed:imageName];

OR, you can use UIDevice class to get that information. It has several methods with boolean returns you can use to get various information about the device:

[[UIDevice currentDevice] platform][[UIDevice currentDevice] hasRetinaDisplay][[UIDevice currentDevice] hasMultitasking]

OR, you can include <sys/sysctl.h> and;

NSString *platform = [self platform];if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";if ([platform isEqualToString:@"iPhone3,3"])    return @"Verizon iPhone 4";if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5 (GSM)";if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";

so on and so forth. You can learn about device strings at here.

There are some other ways to do this programmatically, But as of now, there is no explicit way to do this in the interface builder that I know of. Feel free to point out my mistakes.