views:

1011

answers:

3

When using a UITabBarController, how do you get the size of the tab bar at the bottom ?Similarly, how do you know how much room you have inside the tabbed-view for your content? I see a lot of examples of people sizing their tab child views to [[UIScreen mainScreen] applicationFrame], which can’t be correct because the tab bar takes up some room at the bottom of the screen.

Also, is it possible to modify the size of the tab bar?

Thanks Ryan

A: 

If you can find out how to resize a UITabBar, then you can resize a UITabBarController's UITabBar. You can access the object by taking

[[UITabBarController subviews] objectAtIndex:0]

But it's recommended in the documentation that you don't directly access the object.

Ed Marty
+1  A: 

The reason you can use applicationFrame is that UITabBarController resizes its subcontrollers' views, so as long as your view supports resizing correctly, it'll all work out.

You can get the size of the tab bar by accessing your tab bar controller's tabBar property and looking at its frame. The total size of the tab bar plus the area for the view can be found by looking at the tab bar controller's view property's frame, so a little subtraction will get you the number you're looking for:

CGFloat myViewHeight = tabBarController.view  .size.height
                     - tabBarController.tabBar.size.height;
Brent Royal-Gordon
What sdk version are you using? I am using 2.2.1, and I can't access the tabBar property
Carlos Hernandez
A: 

Hi I want to do the same thing but I tried to add this to my code:

CGFloat myViewHeight = tabBarController.view .size.height - tabBarController.tabBar.size.height;

And it seems UITabBarController does not have a attribute called tabBar.