UINavigationBar高度和横向模式

Jus*_*Sid 4 iphone cocoa-touch objective-c uikit

如果我使用UINavigationController来显示我的UINavigationBar,这个条在横向模式下比在纵向模式下更纤细.

到目前为止一切都很好,因为我想要这个行为,但我有一个视图不是由UINavigationController处理的,所以我只是将一个UINavigationBar从Interface Builder拖放到视图中,但是这个一直都是相同的大小我可以没有办法告诉UINavigationBar它应该调整大小.

谁知道如何实现这一目标?

Hil*_*ell 10

您可以在UIView的layoutSubviews方法中调整导航栏的大小,如下所示:

- (void)layoutSubviews {
    [super layoutSubviews];

    // Let navBar tell us what height it would prefer at the current orientation
    CGFloat navBarHeight = [navBar sizeThatFits:self.bounds.size].height;

    // Resize navBar
    navBar.frame = CGRectMake(0, 0, self.bounds.size.width, navBarHeight);
}
Run Code Online (Sandbox Code Playgroud)