iphone - 创建两个xibs,一个用于iPhone,一个用于iPad

标签 iphone ios ipad interface-builder xib

我将如何创建特定于设备的 xib?我为 iPhone 制作了一个通用的,但如何使用单独的 xib 文件?

最佳答案

来自Apple Resource Programming Guide :

Note: If you are developing a Universal application for iOS, you can use the device-specific naming conventions to load the correct nib file for the underlying device automatically. For more information about how to name your nib files, see “iOS Supports Device-Specific Resources.”

在“iOS Supports Device-Specific Resources”文档中,它是这样说的:

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:

basename - device.filename_extension

The string represents the original name of the resource file. It also represents the name you use when accessing the file from your code. Similarly, the string is the standard filename extension used to identify the type of the file. The string is a case-sensitive string that can be one of the following values:

  • ipad - The resource should be loaded on iPad devices only.
  • iphone - The resource should be loaded on iPhone or iPod touch devices only. You can apply device modifiers to any type of resource file.

因此,如果您想要单独的 .xib 文件,您可以包括名为“MyView-ipad.xib”的 iPad xib 和名为“MyView-iphone.xib”的 iPhone xib。

一旦你将这些文件包含在你的项目中,当你调用它时:

UIViewController *someViewController = [[someViewController alloc] initWithNibName:@"MyView" bundle:nil];

根据您的应用程序运行的设备,将加载正确的 xib 文件。

希望这对您有所帮助!

关于iphone - 创建两个xibs,一个用于iPhone,一个用于iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11404320/

相关文章:

ios - 在 Mac 上加载移动网站

objective-c - EKCalendarChooser 多项选择不起作用

ios - iPad OpenGL ES 极慢 glResolveMultisampleFramebufferAPPLE()

ios - 将 lame mp3 编码器链接到 iOS 应用程序时如何解决 "Undefined symbol init_xrpow_core_sse"?

ios - 通过 Xcode 意外覆盖了 iPhone 设备位置

ios 图片文字和颜色增强滤镜

iphone - 当 iPhone 从 sleep 状态重新打开且应用程序仍处于打开状态时释放

iOS:Airplay 选择器 MPVolumeView 替代品

ios - 应用程序 :openURL: method not being called

iphone - 释放/解除分配标签栏 View Controller