views:

131

answers:

1

I am creating a UIView programatically in loadView. The application has a UITabBarController and UINavigationController.

How do I create a view that automatically resizes when a tab bar and a navigation bar both exist?

My current approach to this problem is calculating the heights of the navigation and tab bar controllers and subtracting them from the mainScreen's height:

float navObjectsHeight = self.tabBarController.tabBar.frame.size.height 
    + self.navigationController.navigationBar.frame.size.height;

CGRect mainFrame = CGRectMake(0, 0, screenFrame.size.width, 
  screenFrame.size.height - navObjectsHeight);

UIView *contentWrapper = [[UIView alloc] initWithFrame:mainFrame];
A: 

The UIView has a property to handle that situation. As you are creating it programatically the code to use is:

UIView *aView = [[UIView alloc] init];
aView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
Ricardo de Cillo
I have had success with the autoresizingMask when creating table views programatically, but not when creating UIViews in loadView.
ddawber
make sure the containing view's frame has the apropriate values. If that doesn't work, then I think you could provide more details.
Ricardo de Cillo
I think the problems I was having were to do with the way in which I was initialising views in loadView. Often it's best to invoke [super loadView] and then instantiate a wrapper view with frame self.view.bounds. Then the autoresizing mask will resize to account for the tab bar controller.
ddawber