简体   繁体   English

将 XIB 加载到 UIView

[英]Load XIB into a UIView

I have a UIView that is not covering the entire screen of an iPhone... about 200 pixels by 300 pixels.我有一个 UIView 没有覆盖 iPhone 的整个屏幕......大约 200 像素 x 300 像素。

I'm trying to load a xib into this view, but it seems to have an issue.我正在尝试将 xib 加载到此视图中,但似乎有问题。 The code works, but the UIView takes over everything at fullscreen... not at the determined width of the UIView.该代码有效,但 UIView 接管了全屏的所有内容……而不是 UIView 的确定宽度。

Here is the code I have:这是我的代码:

incViewPopUP = [[[NSBundle mainBundle] loadNibNamed:@"IncidentsViewController" owner:self options:nil] objectAtIndex:0];

I also tried adding it as a subview like below.. but that also does not work.我也尝试将其添加为如下所示的子视图..但这也不起作用。

UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@"IncidentsViewController" owner:self options:nil] objectAtIndex:0];
[incViewPopUP addSubView:myView];

Thanks for the help!谢谢您的帮助!

Did you try setting the frame size of myview programmatically?您是否尝试以编程方式设置 myview 的帧大小? Set myView.frame = CGRectMake (0,0,320,420)?设置 myView.frame = CGRectMake (0,0,320,420)? Or you can give your favorite value for that frame:)或者您可以为该框架提供您最喜欢的值:)

Adam, try this:亚当,试试这个:

MyViewController *myViewController=[MyViewController alloc] initWithNib:@”IncidentsViewController”];

[myView addSubView:myViewController.view];

[myViewController release];

Just make sure after that the XIB has the right size for your UIView.只需确保之后 XIB 的尺寸适合您的 UIView。

You may need to remove all dummy components such as statusbar and other bars in IB from the view.您可能需要从视图中删除所有虚拟组件,例如状态栏和 IB 中的其他栏。 From that point you can edit the size of the view within IB.从那时起,您可以在 IB 中编辑视图的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM