18

I want to specify different background images for iPhone each device. Like this

iPhone 6 Plus   1242x2208 pixels    bg@3x.png
iPhone 6        750x1334  pixels    bg@2x.png
iPhone 5        640x1136  pixels    bg@2x.png
iPhone 4        640x960   pixels    bg@2x.png
iPhone 3GS      320x480   pixels    bg.png

In LaunchImage there is option available to specify images for Retina HD 4.7 device. So no problem for Launch Images.

enter image description here

In .xcassets file, I have option for 1x, 2x, Retina 4 2x and 3x. But there is no option for iPhone 6 (1334x750) device.

enter image description here

So how to provide 1334x750 px image for iPhone 6 device? Looking for some solution using .xcassets file, not by programmatically loading images for each device.

I have already visited the related SO's questions, but none of them answers specifically for iPhone 6 device images.

iPhone 6 Plus resolution confusion: Xcode or Apple's website? for development

xcode 6 asset catalog iphone 6

Community
  • 1
  • 1
Khawar
  • 9,151
  • 9
  • 46
  • 67

3 Answers3

1

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];
Valar Morghulis
  • 916
  • 1
  • 9
  • 26
1

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

Community
  • 1
  • 1
Abhishek
  • 995
  • 13
  • 28
0

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.

Community
  • 1
  • 1
Kerem
  • 77
  • 9