iPhone:带按钮的UINavigationBar - 调整高度 [英] iPhone: UINavigationBar with buttons - adjust the height

查看:116
本文介绍了iPhone:带按钮的UINavigationBar - 调整高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个兼容两种方向的iPhone应用程序:纵向和横向。

I am working on an iPhone application which works in both orientations: portrait and landscape.

我用于嵌入UINavigationController的一个视图和tableview。此导航栏及其按钮的高度为:44px纵向或34px横向。

I am using for one view and tableview embedded in an UINavigationController. The height of this navigationbar with its buttons is either: 44px portrait or 34px landscape.

在另一个视图中,我自己创建了UINavigationBar,并且我能够设置正确大小的帧,但是带有UIBarButtonItem的嵌入式UINavigationItem不会缩小。因此,对于横向模式中的34 px,此按钮会变大并且会在高度上重叠导航栏。

Within a different view I created the UINavigationBar by myself and I am able to set the frame for the correct size, but the embedded UINavigationItem with UIBarButtonItem doesn't shrink. So for the 34 px in the landscape mode this button is to big and overlaps the navbar in the height.

但有趣的是,这可以使用相同的代码其他应用程序...不知道它不在这里。

The funny thing is though, that this worked with identical code in other apps... have no idea which it isn't here.

无论如何调整UIBarButtonItem的高度/位置?

Is there anyway to adjust the height / position of an UIBarButtonItem?

以下是代码片段:

    navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 34.0f)];
[navBar setBarStyle: UIBarStyleBlackOpaque];

[self addSubview: navBar];

barButton = [[UIBarButtonItem alloc] initWithTitle: NSLocalizedString(@"flip", @"flip") style:UIBarButtonItemStylePlain target:self action:@selector(flip)];

item = [[UINavigationItem alloc] initWithTitle: NSLocalizedString(@"Translation", @"Translation Tab Bar Title")];
[item setRightBarButtonItem: barButton];
[navBar pushNavigationItem:item animated:NO];   

替代文字http://labs.kiesl.eu/images/navbar.png

谢谢

Tom

推荐答案

我想通了:导航栏的高度必须是32像素!使用33或34像素对准螺丝。

I figured it out: The height of the navigation bar must be 32 px! With 33 or 34 px the alignment screws up.

这篇关于iPhone:带按钮的UINavigationBar - 调整高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆