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?
The framespace for the
UIViewControllersbecomes smaller, becauseUINavigationControllermanipulates the view by adding aUINavigationBar, which is 44.0f in size.It gets resized because you replace the view with
self.view = view;If you would have usedaddSubview:instead it would have stayed it’s original size. logancautrell explained when and why.