views:

69

answers:

1

If I use a UINavigationController to display my UINavigationBar, this bar is much slimmer in landscape mode than in portrait mode.

Everything fine so far, as I want this behavior, but I have one view which isn't handled by an UINavigationController and so I just dragged and dropped a UINavigationBar from Interface Builder into the view but this one has always the same size and I can't see a way to tell the UINavigationBar that it should resize.

Anyone knows how to achieve this?

+1  A: 

You can resize the the navigation bar in the layoutSubviews method of your UIView, like so:

- (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, self.bounds.size.height - navBarHeight, self.bounds.size.width, navBarHeight);
}
Hilton Campbell