Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar height and landscape mode

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?

like image 609
JustSid Avatar asked Dec 28 '22 08:12

JustSid


1 Answers

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, 0, self.bounds.size.width, navBarHeight);
}
like image 164
Hilton Campbell Avatar answered Jan 13 '23 16:01

Hilton Campbell