How to get the height of the tabbar programmatically?

给你一囗甜甜゛ 提交于 2019-12-03 04:04:22

问题


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.


回答1:


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

tabBarController?.tabBar.frame.size.height



回答2:


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;



回答3:


prettier

CGRectGetHeight(self.tabBarController.tabBar.frame)



回答4:


check this in your vc

bottomLayoutGuide.length



回答5:


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




回答6:


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




回答7:


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;


来源:https://stackoverflow.com/questions/5388152/how-to-get-the-height-of-the-tabbar-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!