Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS11 customize navigation bar height

First of all, thank you for coming here and help solving my problem. Thank you!!!

In iOS11 beta6, sizeThatFits: seems to not work on UINavigationBar. I notice that UINavigationBar structure has changed by Reveal my app.

I have tried my best to change custom navigation bar's height. But it seems always to be 44, and it works before iOS11.

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = CGSizeMake(self.frame.size.width, 64);
    return newSize;
}

enter image description here

Oddly, I just log its frame in didMoveToSuperview method, its height is 64, but I really see that is 44 in Reveal and app.

I have no idea about this... Help me please.. Thank you.

Update:

I found that about my custom navigation bar LayoutConstraints log in console like this :

"<NSAutoresizingMaskLayoutConstraint:0x604000495ae0 FDCustomNavigationBar:0x7fe2f01399d0.(null) == 42>",
"<NSAutoresizingMaskLayoutConstraint:0x604000495b30 FDCustomNavigationBar:0x7fe2f01399d0.height == 44>"`

bug I even no use auto layout in my navigation bar. What's wrong with it?

Update 8/28 :

enter image description here

I have set my custom navigation bar's subviews frame at navigation bar's - layoutSubviewsmethod.

- (void)layoutSubviews {
    [super layoutSubviews];

    self.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), 64);

    for (UIView *view in self.subviews) {

        if([NSStringFromClass([view class]) containsString:@"Background"]) {
            view.frame = self.bounds;
        } else if ([NSStringFromClass([view class]) containsString:@"ContentView"]) {
            CGRect frame = view.frame;
            frame.origin.y = 20;
            frame.size.height = self.bounds.size.height - frame.origin.y;
            view.frame = frame;
        }
    }
}

but the navigation bar will cover view controller's view. How can I fix that?

like image 779
Jerry4me Avatar asked Aug 24 '17 08:08

Jerry4me


People also ask

What is the height of navigation bar?

Personally I feel most comfortable using a navbar height of 64px. It is enough height to accommodate a logo, and there is room enough to use text in combination with symbols.

What is the height of navigation bar iPhone?

On iPhone tab bars remain 49 points tall in portrait and 32 points tall in landscape.

Can you change iPhone navigation bar?

Change the Bar StyleA user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.


1 Answers

Since iOS 11 UINavigationBar fully supports Auto Layout (this is the reason why you're seeing its constraints). I've opened a radar to Apple because I thought that setting a height constraint to the titleView would have adjusted the navigation bar height accordingly. However this is what Apple replied:

Full support for auto layout does not imply that your view can influence other aspects of the layout of the navigation bar – in particular, the navigation bar enforces its own height and does not allow the title view or other custom views to exceed the height of the navigation bar. We are continuing to work on this issue, and will follow up with you again.

As of today the radar is still open.

like image 98
emix Avatar answered Sep 24 '22 22:09

emix