我有一个名为 abc.png 大小为 320 x 156 的图像在 iPhone 4 上运行良好,还有一个名为 abc@2x.png 大小为 640 x 312 的图像也可以正常工作。但是什么时候请告诉我如何使用iPhone 6设备的图像?
2 回答
首先,目前还没有像 iPhone6 这样的东西,它要么是 iOS6 要么是 iPhone 5。但我猜你说的是屏幕分辨率为 640X1136 的 iPhone 5。没有为 iPhone 5 选择图像的内置方法。
如果您在 resources 中有 abc.png 和 abc@2x.png ,并且您使用如下代码:
UIImage * image = [UIImage imageNamed:@"abc.png"];
它将选择 abc.png 用于非视网膜显示和 abc@2x.png 用于视网膜显示(包括 iPhone 4S 和 iPhone 5)。
如果要为 iPhone 5 加载单独的图像,则需要检查屏幕高度:
if(screenHeight == 480)
{
//iphone 3,3G,4
}
else if(screenHeight == 960)
{
//iphone 4S
}
else if(screenHeight == 1136)
{
//iphone 5
}
这样,您可以为不同的 iphone 加载不同的图像。如果它回答了您的问题,请升级并检查答案。
The answer to your question, I'm afraid to say, is something called AutoLayout. That's the solution Apple came up with to deal with the different form factor for iOS 6 views. Only @2x images are available, but with AutoLayout, you can tell it exactly how to behave.
Here's a nice tutorial on how to use AutoLayout, I tried it and it works well:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2