简体   繁体   中英

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.

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!

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:)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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