如何以编程方式获取标签栏的高度?
我发现 UITabBar 的高度是 49px(或 50px,取决于源)。
因为我不喜欢在代码中使用太多硬编码值,所以我想知道是否可以以编程方式检索选项卡栏的高度。
亲切的问候,
Niels R.
PS:我问的原因是因为我有一个视图控制器(带有包含文本字段的列表视图),它要么简单地由导航控制器(pushViewController)推送,要么呈现为模态(presentModalViewController)。一旦键盘出现,视图的大小就会减小,但我必须考虑到选项卡栏仅在视图控制器被推动时才可见,而不是作为模式呈现。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我不太明白你的PS,但你可以这样做:
I don't totally understand your P.S., but you can do:
如果你想获得 UITabBar 控件的标准高度,那么你可以这样做:
If you want to get the standard height for the UITabBar control then you can do:
更漂亮
prettier
在你的 vc 中检查这个
check this in your vc
在 Swift 3 中,您可以使用下面的代码检索
UITabBar
的高度。self.tabBarController!.tabBar.frame.size.height
这将返回高度的
CGFloat
值In
Swift 3
, you can retrieve the height of theUITabBar
with this code below.self.tabBarController!.tabBar.frame.size.height
Which will return a
CGFloat
value of the height如果一个对象基于 UIView(库中大多数视觉元素都是),您可以从 ivar“frame”获取大小。
If an object is based on UIView (which most visual elements in the library are), you can get the size from the ivar "frame".
UITabBar
继承自UIView
只要您有权访问您的 UITabBar 实例,您就可以访问和修改 UITabBar 的框架,UITabBar
is inherited fromUIView
as long as you mhave access to your UITabBar instance you can access and modify the frame of UITabBar,尝试像这样使用标签栏的intrinsicContentSize属性
Try to use the intrinsicContentSize property of the tab bar like this