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

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

iOS Universal Development – Use of Tilde Sign (~) in Xib File and Image Name for differentiation

iphoneobjective-ciosxcode

提问by Paresh Navadiya

While developing universal apps, we have to write a conditional codefor each device– the iPadas well as the iPhone. In this scenario, the proper use of tildecan 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 / xibfiles.

魔法~会帮助你。您可以使用它来区分 iPhone 和 iPad 资产/xib文件。

Your file should end with ~iphone.xibor ~ipad.xib.

您的文件应以~iphone.xib或结尾~ipad.xib

Note:It's case sensitivedon't use iPador iPhone.

注:这是区分大小写不使用iPadiPhone

Check that each xibfile 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

官方文档InfoPlistKeyReference