Xcode 4.5背景图片iPhone 4,4s,5

Pet*_*ter 6 iphone screen ios ios6 iphone-5

我在我的viewController.m中编写了后台代码:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]];
Run Code Online (Sandbox Code Playgroud)

我有不同图片的正确名称:

image.png for non-retina display (320x480)

image@2x.png for retina display (640x960)

image-568h@2x.png for iPhone 5 (640x1136)
Run Code Online (Sandbox Code Playgroud)

但是当我在模拟器中运行它时,它不需要用于iPhone 5屏幕的image-568h@2x.png它只需要图像@ 2x用于4s屏幕并将其缩放以适应屏幕...我不知道是否有任何编码使用image-568h @ 2x for iPhone 5屏幕?

我正在使用Xcode 4.5

The*_*heQ 13

iPhone 5是视网膜,就像iPhone 4和4S一样,@ 2x图像将自动用于所有这些设备.对于iPhone 5,它只是启动图像被称为"-568h @ 2x".你需要编写一些代码来使用不同的图像,这样的东西可以工作:

NSString *filename = @"image.png";
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (screenRect.size.height == 568.0f)
    filename = [filename stringByReplacingOccurrencesOfString:@".png" withString:@"-568h.png"];

imageView.image = [UIImage imageNamed:filename];
Run Code Online (Sandbox Code Playgroud)