How to get the height of the tabbar programmatically?

IosIphoneUikitUitabbarcontrollerUitabbar

Ios Problem Overview


I've found out that the height of a UITabBar is 49px (or 50px, depending on the source).

Because I don't like to use too much hard-coded values in my code I was wondering if it is possible to retrieve the height of the tabbar programmatically.

Kind regards,
Niels R.

PS: The reason I'm asking is because I have a view controller (with a list view containing text fields) that is either simply pushed by the navigationcontroller (pushViewController) or presented as a modal (presentModalViewController). As soon as the keyboard show up, the size of the view is reduced, but I have to take into account that the tabbar is only visible when the view controller is pushed and not presented as a modal.

Ios Solutions


Solution 1 - Ios

I don't totally understand your P.S., but you can do:

tabBarController?.tabBar.frame.size.height

Solution 2 - Ios

If you want to get the standard height for the UITabBar control then you can do:

    UITabBarController *tabBarController = [UITabBarController new];
    CGFloat tabBarHeight = tabBarController.tabBar.frame.size.height;

Solution 3 - Ios

prettier

CGRectGetHeight(self.tabBarController.tabBar.frame)

Solution 4 - Ios

check this in your vc

bottomLayoutGuide.length

Solution 5 - Ios

In Swift 3, you can retrieve the height of the UITabBar with this code below.

self.tabBarController!.tabBar.frame.size.height

Which will return a CGFloat value of the height

Solution 6 - Ios

If an object is based on UIView (which most visual elements in the library are), you can get the size from the ivar "frame".

Solution 7 - Ios

UITabBar is inherited from UIView as long as you mhave access to your UITabBar instance you can access and modify the frame of UITabBar,

CGRect myRect = myTabBar.frame;

Solution 8 - Ios

Try to use the intrinsicContentSize property of the tab bar like this

let tabBarHeight = self.tabBarController.tabBar.intrinsicContentSize.height

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNiels R.View Question on Stackoverflow
Solution 1 - IosMasonView Answer on Stackoverflow
Solution 2 - IosFederico JordanView Answer on Stackoverflow
Solution 3 - IosNick GinantoView Answer on Stackoverflow
Solution 4 - IosAdam SmakaView Answer on Stackoverflow
Solution 5 - IosCyrilView Answer on Stackoverflow
Solution 6 - IosHack SawView Answer on Stackoverflow
Solution 7 - IosJhaliya - Praveen SharmaView Answer on Stackoverflow
Solution 8 - IosiPhoneDeveloperView Answer on Stackoverflow