ios 如何在通用应用程序中同时支持 iPad 和 iPhone 视网膜图形

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9611061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:12:49  来源:igfitidea点击:

How to support both iPad and iPhone retina graphics in universal apps

iphoneiosipadretina-display

提问by rowwingman

Apple presented new iPad that support retina graphics.

苹果推出了支持视网膜图形的新 iPad。

I saw this link retina graphic in apple apps. As you can see apple just use "@2x" suffix for retina iPad display.

在苹果应用程序中看到了这个链接视网膜图形。正如你所看到的,苹果只为视网膜 iPad 显示使用“@2x”后缀。

I have an universal app. So how to support retina in new iPad andiPhone? Will iPad retina use suffix "@2x" similar to iPad?

我有一个通用的应用程序。那么如何在新的 iPadiPhone 中支持视网膜呢?iPad Retina 会使用类似于 iPad 的后缀“@2x”吗?

回答by rowwingman

I just created a test app and tested.

我刚刚创建了一个测试应用程序并进行了测试。

So for devices without retina:
ImageName.png- For iPhone/iPod
ImageName~ipad.png-- For iPad

所以对于没有视网膜的设备:
ImageName.png- 对于 iPhone/iPod
ImageName~ipad.png-- 对于 iPad

For devices with retina display:
[email protected]- For iPhone/iPod
ImageName@2x~ipad.png-- For iPad

对于配备 Retina 显示屏的设备:
[email protected]- 对于 iPhone/iPod
ImageName@2x~ipad.png-- 对于 iPad

And you can still use @2x if your iPhone high resolution image and iPad high resolution image have the same size.
To load the image just use [UIImage imageNamed:@"ImageName.png"];
I just tested it on iOS simulator for iOS 5.1, 5.0 and 4.3.
By the way why you should use @2x and nothing more.

如果您的 iPhone 高分辨率图像和 iPad 高分辨率图像大小相同,您仍然可以使用 @2x。
要加载图像,[UIImage imageNamed:@"ImageName.png"];
我刚刚在 iOS 5.1、5.0 和 4.3 的 iOS 模拟器上对其进行了测试。
顺便说一下,为什么您应该使用 @2x 而仅此而已。

The main thing because you shouldn't use the same graphics on iPhone and iPad, because iPhone and iPad has different size. And if you will use the same size the graphics will already done for you iPad retina display (if you previously use iPhone retina display). If you will images with different size, so you will use different image names for iPhone and iPad. So in this side you need just add @2x suffix. That's why you should use just @2x suffix. - these are my thoughts.

主要是因为您不应该在 iPhone 和 iPad 上使用相同的图形,因为 iPhone 和 iPad 的尺寸不同。如果您将使用相同尺寸的图形,则 iPad 视网膜显示已经完成(如果您以前使用 iPhone 视网膜显示)。如果您要使用不同尺寸的图像,那么您将为 iPhone 和 iPad 使用不同的图像名称。所以在这一边你只需要添加@2x 后缀。这就是为什么你应该只使用 @2x 后缀的原因。——这是我的想法。

回答by bdalziel

I found that the iPad mini/non retina iPad hardware, not simulator, would fall back on ImageName.png, not ImageName~ipad.png as you would expect from rowwingman's answer.

我发现 iPad mini/非视网膜 iPad 硬件,而不是模拟器,会依赖 ImageName.png,而不是 ImageName~ipad.png,正如你从 rowwingman 的回答中所期望的那样。

Looking at the docs, referenced in another StackOverflow questionby Nate, it seems as though appending the device to iphoneimages is the correct way to do it.

综观文档,在另一个引用的StackOverflow问题内特,却仿佛设备附加到iphone的图像是做了正确的道路。

MyImage.png- Default version of an image resource.

[email protected]- High-resolution version of an image resource for devices with Retina displays.

MyImage~iphone.png- Version of an image for iPhone and iPod touch.

MyImage@2x~iphone.png- High-resolution version of an image for iPhone and iPod touch devices with Retina displays.

Image, Sound, and Video Resources

MyImage.png- 图像资源的默认版本。

[email protected]- 高分辨率版本的 Retina 显示器设备图像资源。

MyImage~iphone.png- 适用于 iPhone 和 iPod touch 的图像版本。

MyImage@2x~iphone.png- 适用于配备 Retina 显示屏的 iPhone 和 iPod touch 设备的高分辨率图像。

图像、声音和视频资源