在Interface Builder中为通用应用创建单个.xib? (IOS) [英] Create single .xib for Universal app in Interface Builder? (iOS)

查看:97
本文介绍了在Interface Builder中为通用应用创建单个.xib? (IOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

道歉,如果这是一个愚蠢的问题,但我已经做了一些谷歌搜索和搜索SO,并没有找到任何人问这个确切的问题。

Apologies if this is a silly question, but I've done some googling and searched SO and haven't found anyone asking this exact question.

我一直在做iOS开发已有一段时间了,但我对Interface Builder完全不熟悉。我想知道的是:有没有办法只创建一个.xib文件,然后在Universal应用程序中将它用于iPhone和iPad?

I have been doing iOS development for some time now, but I am completely new to the Interface Builder. What I want to know is this: is there any way to just create ONE .xib file and then use it for both iPhone and iPad in a Universal application?

我必须单独创建它们似乎很愚蠢;当我在代码中做一次(对屏幕尺寸进行微调)时,为什么会在Interface Builder中多次放置一些工作?

It seems silly to me to have to create them separately; why do twice the work laying something out more than once in Interface Builder when I could do it once (with minor adjustments for screen size) in code?

请告诉我如果我在这里失踪/误解了什么。就像我说的,我是一个完整的Interface Builder新手:)

Please let me know if I'm missing/misunderstanding something here. Like I said, I'm a complete Interface Builder newbie :)

编辑:我过去曾向iPhone App Store提交过非界面构建器游戏和iPad的版本完全相同,所以我并不担心每个设备上的游戏外观/感觉都不同。我希望它们看起来完全相同,除了由于宽高比的差异导致的一些轻微的定位变化。

I have submitted non-interface-builder games to the App Store in the past where the iPhone and iPad versions were identical, so I'm not concerned with making the game look/feel different on each device. I intend for them to look exactly the same, aside from some slight positioning changes due to the difference in aspect ratio.

推荐答案

如果你知道结果视图会是什么样子,基于自动调整,你确实只能使用一个 .xib 。如果视图只是某种自动化的共享组件,可能会派上用场。但是,如果你需要iPad上的视图看起来与iPhone不同,只需使用两个 .xib 。然后可以根据需要加载适当的一个,例如在实例初始化器中,如此控制器的-init:

If you know what the resulting view would look like, based on autoresizing, you can indeed use only one .xib. May come in handy if the view is just some sort of a shared component that autoresizes as you want it to. However, if you need the view to look way different on iPad than on iPhone, just use two .xibs. It’s possible then to load the appropriate one as needed, for example in instance initializer, like this controller’s -init:

- (id)init
{
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
         self = [super initWithNibName:@"YourNibForPad" bundle:nil];
    }
    else
    {
         self = [super initWithNibName:@"YourNibForPhone" bundle:nil];
    }
    if (self) { /* initialize other ivars */ }
    return self;
}

这篇关于在Interface Builder中为通用应用创建单个.xib? (IOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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