iOS通用开发 - 在Xib文件和图像名称中使用Tilde Sign(〜)进行区分 [英] iOS Universal Development – Use of Tilde Sign (~) in Xib File and Image Name for differentiation

查看:82
本文介绍了iOS通用开发 - 在Xib文件和图像名称中使用Tilde Sign(〜)进行区分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发通用应用时,我们必须为每个设备写一个条件代码 - iPad 以及 iPhone 。在这种情况下,正确使用 tilde 可能非常有用。

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.

例如,如果你想推新的视图控制器,然后你必须写很多行(几乎10)代码:

For example, if you want to push new view controller, then you’d have to write lot of lines (almost 10) of code:

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];
}

我们如何区分iphone和ipad的图像?

推荐答案

区分iPhone和iPad的XIB文件

神奇的会对你有所帮助。您可以使用它来区分iPhone和iPad资产/ xib 文件。

The magical ~ will help you. You can use it, to differentiate between iPhone and iPad assets / xib files.

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

注意: 区分大小写不要使用 iPad iPhone

检查每个 xib 文件已连接所有插座并且设置了正确的文件所有者。如果缺少一些,iOS可能决定不使用它们而是使用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.

用于区分iphone和ipad的图像

特定于平台的修饰符 - 使用修饰符~iphone或~ipad指定针对特定设备大小的图像。

Platform-specific modifiers—Use the modifiers ~iphone or ~ipad to specify images targeting a specific size of device.

官方文件 InfoPlistKeyReference

这篇关于iOS通用开发 - 在Xib文件和图像名称中使用Tilde Sign(〜)进行区分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆