Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView frame when navigation bar and tab bar controller exist

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];
like image 917
dianovich Avatar asked Sep 10 '10 20:09

dianovich


1 Answers

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;
like image 50
Ricardo de Cillo Avatar answered Oct 04 '22 22:10

Ricardo de Cillo