如何以编程方式获取标签栏的高度?

发布于 2024-10-24 06:12:50 字数 294 浏览 1 评论 0原文

我发现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

可爱暴击 2024-10-31 06:12:51

我不太明白你的PS,但你可以这样做:

tabBarController?.tabBar.frame.size.height

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

tabBarController?.tabBar.frame.size.height
久随 2024-10-31 06:12:51

如果你想获得 UITabBar 控件的标准高度,那么你可以这样做:

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

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;
木槿暧夏七纪年 2024-10-31 06:12:51

更漂亮

CGRectGetHeight(self.tabBarController.tabBar.frame)

prettier

CGRectGetHeight(self.tabBarController.tabBar.frame)
执妄 2024-10-31 06:12:51

在你的 vc 中检查这个

bottomLayoutGuide.length

check this in your vc

bottomLayoutGuide.length
卸妝后依然美 2024-10-31 06:12:51

在 Swift 3 中,您可以使用下面的代码检索 UITabBar 的高度。

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

这将返回高度的 CGFloat

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

陌伤ぢ 2024-10-31 06:12:51

如果一个对象基于 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".

唯憾梦倾城 2024-10-31 06:12:51

UITabBar 继承自 UIView 只要您有权访问您的 UITabBar 实例,您就可以访问和修改 UITabBar 的框架,

CGRect myRect = myTabBar.frame;

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;
嗳卜坏 2024-10-31 06:12:51

尝试像这样使用标签栏的intrinsicContentSize属性

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

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

let tabBarHeight = self.tabBarController.tabBar.intrinsicContentSize.height
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文