xcode iOS 通用开发——在 Xib 文件和图像名称中使用波浪号 (~) 进行区分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13742930/
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
iOS Universal Development – Use of Tilde Sign (~) in Xib File and Image Name for differentiation
提问by Paresh Navadiya
While developing universal apps
, we have to write a conditional code
for each device
– the iPad
as well as the iPhone
. In this scenario, the proper use of tilde
can be extremely beneficial.
在发展universal apps
中,我们必须写一个conditional code
每个device
-的iPad
还有iPhone
。在这种情况下,正确使用tilde
可能会非常有益。
For example, if you want to push new view controller, then you'd have to write lot of lines (almost 10) of code:
例如,如果要推送新的视图控制器,则必须编写很多行(几乎 10 行)的代码:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@”MasterViewController_iphone” bundle:nil];
[self.navigationController pushViewController:masterViewController animated:YES];
[masterViewController release];
}
else
{
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@”MasterViewController_ipad” bundle:nil];
[self.navigationController pushViewController:masterViewController animated:YES];
[masterViewController release];
}
How can we differentiate images for iphone and ipad?
我们如何区分 iphone 和 ipad 的图像?
回答by Paresh Navadiya
For differentiating XIB file for iPhone and iPad:
用于区分 iPhone 和 iPad 的 XIB 文件:
The magical ~
will help you. You can use it, to differentiate between iPhone and iPad assets / xib
files.
魔法~
会帮助你。您可以使用它来区分 iPhone 和 iPad 资产/xib
文件。
Your file should end with ~iphone.xib
or ~ipad.xib
.
您的文件应以~iphone.xib
或结尾~ipad.xib
。
Note:It's case sensitivedon't use iPad
or iPhone
.
注:这是区分大小写不使用iPad
或iPhone
。
Check that each xib
file has all outlets connected and has the correct fileowner set. If some are missing, iOS could decide not to use them and use the iPhone files instead.
检查每个xib
文件是否已连接所有出口并设置了正确的文件所有者。如果缺少某些文件,iOS 可以决定不使用它们,而是使用 iPhone 文件。
For differentiating Images for iphone and ipad
用于区分 iphone 和 ipad 的图像
Platform-specific modifiers—Use the modifiers ~iphone or ~ipad to specify images targeting a specific size of device.
特定于平台的修饰符 - 使用修饰符 ~iphone 或 ~ipad 指定针对特定设备尺寸的图像。
Official document InfoPlistKeyReference