Load XIB into a UIView

怎甘沉沦 提交于 2019-12-11 02:04:49

问题


I have a UIView that is not covering the entire screen of an iPhone... about 200 pixels by 300 pixels.

I'm trying to load a xib into this view, but it seems to have an issue. The code works, but the UIView takes over everything at fullscreen... not at the determined width of the 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!


回答1:


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.




回答2:


Did you try setting the frame size of myview programmatically ? Set myView.frame = CGRectMake (0,0,320,420) ? Or you can give your favorite value for that frame :)




回答3:


You may need to remove all dummy components such as statusbar and other bars in IB from the view. From that point you can edit the size of the view within IB.



来源:https://stackoverflow.com/questions/6797517/load-xib-into-a-uiview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!