ios - Xcode 4.5 背景图像 iPhone 4、4s、5

标签 ios iphone ios6 screen iphone-5

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

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]];

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

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

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

image-568h@2x.png for iPhone 5 (640x1136)

但是当我在模拟器中运行它时,它不会为 iPhone 5 屏幕使用 image-568h@2x.png 它只为 4s 屏幕使用 image@2x 并缩放它以适合屏幕...我不知道是否有任何代码可以使用 iPhone 5 屏幕的 image-568h@2x?

我正在使用 Xcode 4.5

最佳答案

iPhone 5 是 retina,就像 iPhone 4 和 4S,@2x-image 将自动用于所有这些设备。对于 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];

关于ios - Xcode 4.5 背景图像 iPhone 4、4s、5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13070369/

相关文章:

iphone - 如何在 Landscape 而不是 Portrait 中显示 UIImagePickerControllerSourceTypeCamera

iphone - 在导航 View Controller 中加载特定场景

ios - 代号一-iOS发布

iphone - 使用 .xib 文件是最佳做法吗?

ios - 解析文件查询和 Swift 1.2 错误 - getDataInBackgroundWithBlock

javascript - Sencha touch 中的数字签名选项

iphone - 由于 iPhone 中的默认调用,UI 受到干扰

iphone - 来自 YouTube 的缩略图

ios - 防止 UIWebView 在键盘出现时滚动

ios - swift : PickerView selectedRow(inComponent:0) doesnt return -1 when nothing selected