I have several UIViewControllers, loaded via a UINavigationController, where I override loadView, and setup a custom view to display. I am having problems with setting the frames of some of the subviews, and maybe the view itself. I think that either the UINavigationController or the UIViewController is able to force it's view to fill the screen when displayed.
I am wondering if and/or when the size of the view is set. And if it is happening, is it setting the frame of the view, or doing it another way.
Thanks.
Update:
I have just noticed while working through this is that I make an new UINavigationController, with this loadView method:
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 10.0f, 10.0f)];
[view setBackgroundColor:[UIColor redColor]];
self.view = view;
[view release];
}
I get a red view taking up the entire screen, except for the status bar and header. When does my view get resized to fill the screen? And what size should I use when creating the view?
Best Answer
UINavigationController will automagically size a ViewController's view when pushed. From the docs:
If you want to have a smaller view displayed then you'll have to create a container and make it a child of your VC's view, setting the size manually. The autoresize mask may have to be set properly, depending on how you create the view.