gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:17:02 26 4
gpt4 key购买 nike

我将如何创建特定于设备的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com