在 Xcode 中为 iPad 指定图像,如 iPhone 4 的 @2x
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5535630/
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
Specify images for iPad in Xcode like @2x for iPhone 4
提问by Fernando Redondo
I have upgraded my current target to iPad and made a universal app and the time for adjusting my iphone app to ipad would decrease significantly if there is an answer for this question.
我已经将我当前的目标升级到 iPad 并制作了一个通用应用程序,如果这个问题有答案,我将我的 iphone 应用程序调整到 ipad 的时间将大大减少。
By this time everybody know that if you have a image called "football.png" and want support for Retina Display you should double the size of the image and call it "[email protected]".
这时候大家都知道,如果你有一个名为“ football.png”的图像并且想要支持 Retina Display,你应该将图像的大小加倍并命名为“ [email protected]”。
My question is if there is something for iPad like *football@iPad_which_is_another_size.png*?
我的问题是 iPad 是否有像 *football@iPad_which_is_another_size.png* 这样的东西?
If there isn't a way to do this, do I have to connect every image to an IBOutlet and set the frame programmatically?
如果没有办法做到这一点,我是否必须将每个图像连接到 IBOutlet 并以编程方式设置框架?
回答by Luca Bernardi
In iOS 4.0 and later, it is possible to mark individual resource files as usable only on a specific type of device To associate a resource file with a particular device, you add a custom modifier string to its filename. The inclusion of this modifier string yields filenames with the following format:
在 iOS 4.0 及更高版本中,可以将单个资源文件标记为仅在特定类型的设备上可用 要将资源文件与特定设备关联,您可以在其文件名中添加自定义修饰符字符串。包含此修饰符字符串会生成具有以下格式的文件名:
<basename><device>.<filename_extension>
To load the iPad specific resources you should use ~ipad
. Example: create the image named AwesomeImage~ipad.png
and load with [UIImage imageNamed:@"AwesomeImage.png"]
like you do for retina display image.
要加载特定于 iPad 的资源,您应该使用~ipad
. 示例:创建命名AwesomeImage~ipad.png
并加载的图像,[UIImage imageNamed:@"AwesomeImage.png"]
就像您为视网膜显示图像所做的那样。
For more information: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/Introduction/Introduction.htmlAt "iOS Supports Device-Specific Resources" section.
有关更多信息:http: //developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/Introduction/Introduction.html在“iOS 支持设备特定资源”部分。
回答by jn_pdx
I don't think there's a way to get the OS to pick it automatically for you, like there is for the Retina display. But, you could create a convenience method to return your filenames for you like:
我认为没有办法让操作系统自动为您选择它,就像 Retina 显示器那样。但是,您可以创建一个方便的方法来为您返回文件名,例如:
-(NSString*) myImageFilename:(NSString*)baseName withExtension:(NSString*)ext {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return [NSString stringWithFormat:"%@@iPadSize.%@"];
} else {
return [NSString stringWithFormat:"%@.%@"];
}
}