Jaume
Jaume

Reputation: 3800

xcode get UITabBar height

My app has a tabBarController as main controller and I need to get the height of tabBar from any view controller in order to calculate proper position for the rest of elements. How to get it programmatically? Thank you.

Upvotes: 7

Views: 11397

Answers (2)

Miroslav Hrivik
Miroslav Hrivik

Reputation: 892

For Swift use this:

let tabBarHeight = tabBarController?.tabBar.bounds.size.height ?? 0

It returns tabBar height when tabBarController is not nil, otherwise 0.

Upvotes: 4

Jason Coco
Jason Coco

Reputation: 78393

I strongly suggest setting up your view hierarchy such that outer views are autosized by the container view and then more specific inner views can check the bounds of the outer layout view and lay themselves out appropriately at the appropriate times.

However, if your requirement makes that impossible (or extremely complicated and you really do need to specify points for everything), you can get the height of the tab bar with UIViewController's tabBarController property:

// from inside the view controller
CGSize tabBarSize = [[[self tabBarController] tabBar] bounds].size;

Upvotes: 17

Related Questions