UIToolbar 与 UINavigationController 大小调整

发布于 2024-12-15 11:56:36 字数 358 浏览 4 评论 0原文

我有一个 UIToolbar 作为 rightBarButtonItem 和我的 UINavigationController。我这样创建它:

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 275, 44.01)];

在 iPad 4.3 模拟器中,它看起来正确并且与 UINavigationBar 的高度对齐。但当我在 iPad 5.0 模拟器中运行它时,它看起来太小了。 UIToolbar 的高度是否存在正确的特定设置?谢谢。

I have a UIToolbar as the rightBarButtonItem with my UINavigationController. I create it like this:

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 275, 44.01)];

In the iPad 4.3 simulator, it looks correct and lines up with the UINavigationBar's height. But when I run it in the iPad 5.0 simulator, it looks too small. Is there a certain setting for the height of the UIToolbar that is correct? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

喵星人汪星人 2024-12-22 11:56:36

如果您利用 Interface Builder 及其提供的所有功能,您就可以避免所有此类问题。

您在代码中执行此操作有具体原因吗?即使您坚持在那里这样做,您也不应该硬编码您的价值观。您应该从视图的框架/边界获取宽度和/或将值放入定义的常量中:

self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake( 0.0, 0.0, self.view.bounds.size.width, kStdToolbarHeight )];

只是好奇,为什么必须将工具栏高度设置为 44.01 而不是 44.0?

You'd avoid the entire category of these kinds of issues if you took advantage of Interface Builder and all it had to offer.

Do you have a specific reason for doing this in code? Even if you insist on doing it there, you shouldn't be hardcoding your values. You should be getting the width from the view's frame/bounds and/or putting the values into defined constants:

self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake( 0.0, 0.0, self.view.bounds.size.width, kStdToolbarHeight )];

Just curious, why do you have to toolbar height set to 44.01 and not 44.0?

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