Question

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

Was it helpful?

Solution

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;

OTHER TIPS

Old question, but anyway:

If you do not load your view from a NIB, set the auto resizing flags in your loadView func; something like this:

self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |
                             UIViewAutoresizingFlexibleWidth;

If you do so, you can use [[UIScreen mainScreen] applicationFrame] to specify your view's frame; it will be resized automatically if a tab bar is present.

If you have a NIB for your view, the autoresizingMask is set automatically by Interface Builder.

Markus

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top