通用应用程序iPad/iPhone图像命名约定?
在我的应用程序中,我需要根据设备 iPad/iPhone 4/iPhone 3 设备获取正确的图像。
例如:
我有一个名为 a.png
(宽度 40,高度 20)的 iPhone 3/iPod 图像,以及 [email protected]
(宽度 80,高度 40),适用于 iPhone 4。
如果我提到 myImage 包含的代码
UIImage *myImage=[UIImage imageNamed:@"a.png"];
(80*40)图像(如果是 iPhone 4)。 如果是 iPod/iPhone 3,myImage 包含 (40*20) 图像。
我的问题是如何像上面的命名约定一样获取 iPad (60*30) 的图像。
我尝试将 a~ipad.png
作为图像名称,但它不起作用。能指出哪里有错误吗?
如果我使用 [UIDevice currentDevice];
isIpod -> 条件加载(60*30)图像 否则加载 iPhone/iPod 的图像它工作正常。
但我需要让它在不使用条件的情况下工作,并使用命名约定,例如 iPhone/iPod 的 a.png
,[电子邮件受保护]
适用于 iPhone 4,同样适用于 iPad。
提前致谢。
In my application I need to get the correct image based on the device iPad/iPhone 4/iPhone 3 device.
For example:
I have an image named a.png
(width 40,height 20) for iPhone 3/iPod, and [email protected]
(width 80,height 40) for iPhone 4.
If I mentioned the code
UIImage *myImage=[UIImage imageNamed:@"a.png"];
myImage contains (80*40) image if it's iPhone 4.
myImage contains (40*20) image if it's iPod/iPhone 3.
My question is how do I get the image for iPad (60*30) like above naming convention.
I tried giving a~ipad.png
as an image name and it's not working. Can you point out where there is a mistake?
And if I use the condition using [UIDevice currentDevice];
isIpod -> load(60*30) image
otherwise load images for iPhone/iPod it's working fine.
But I need to get it to work without using the condition, and using the naming convention like a.png
for iPhone/iPod, [email protected]
for iPhone 4 and likewise for iPad.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道这是旧帖子,但我认为屏幕截图给出了有关命名约定的更清晰的想法。
使用最新设备:button@3x~iphone.png 和 按钮@3x~ipad.png
I know it is old post, but I think Screenshot gives more clear idea about naming convention.
With latest devices: button@3x~iphone.png and button@3x~ipad.png
根据这个Apple文档,设备有一个图像命名约定:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html#//apple_ref/doc/uid /10000051i-CH7-SW17
iPhone 表示使用“~iphone”,iPad 表示无后缀。尽管有传闻说“~ipad”也可以使用。
According to this Apple doc, there is an image naming convention for devices:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html#//apple_ref/doc/uid/10000051i-CH7-SW17
It says to use "~iphone" for iPhone, and no suffix for iPad. Though anecdotally I have been told that "~ipad" also works.
iPad 没有图像命名约定,仅适用于视网膜显示屏,以便您的图像显得清晰。如果您想支持 iPad,那么您需要为其创建一个单独的布局(单独的 xib),在大多数情况下甚至需要创建一组单独的图像,因为您获得了更大的布局。
但是,您可以为自己创建命名约定,并将字符串名称传递给静态函数,该函数将根据设备将名称转换为 iPad/iPhone。
例如
,在 getImageName 函数内,您可以进行转换(如果是 iphone,则使用相同的名称,否则重命名为其他名称)
There is no image naming convention for iPad, it's only for retina displays so that your images will appear crisp. If you want to support iPad then you need to create a separate layout for it (separate xib), even separate set of images in most cases because you were given a bigger layout.
You can, however, create a naming convention for yourself and pass the string name to a static function that will convert the name to an iPad / iphone depending on the device.
E.g.
and inside the getImageName function, you can do your conversion (use the same name if iphone, else rename to something else)
除了 Nate 的帖子之外,Apple 描述命名约定的具体文档可以在以下位置找到:
支持高分辨率屏幕 - 更新您的图像资源文件
根据链接,命名约定模式如下:
例如:“MyImage@2x~ipad .png”用于高分辨率 iPad 特定图像,或“MyImage~iphone.png”用于标准分辨率 iPhone 特定图像。
Further to Nate's post, the specific documentation from Apple describing the naming convention can be found at:
Supporting High-Resolution Screens - Updating Your Image Resource Files
According to the link, the naming convention pattern is as follows:
<ImageName><device_modifier>.<filename_extension>
<ImageName>@2x<device_modifier>.<filename_extension>
For example: "MyImage@2x~ipad.png" for a high-res iPad-specific image or "MyImage~iphone.png" for a standard-res iPhone-specific image.
我正在使用在创建任何应用程序之前首先开发的“资源管理器”。
该资源管理器可以在加载资源配置文件(主要是 XML)后决定命名约定。
这样,一切对于 GUI 程序员来说都是透明的,您只需要担心创建内容:)
I am using a "Resource Manager" that I developed first before creating any application.
This Resource Manager can decide about the naming convention after loading the resource configuration files (mostly XML).
This way everything is transparent to the programmer of the GUI, you only need to worry about creating the content :)