How to increase the height of UINavigationBar?

2019-04-30 05:24发布

Simple question: How can I increase the height of the navigation bar so that additional widgets will fit in there while keeping the blur?

Examples are the Calendar app where weekday abbreviations are added to the bottom of the navigation bar...

Calendar app

...and in Mail when you move the mail to a different folder:

Mail app

3条回答
来,给爷笑一个
2楼-- · 2019-04-30 06:04

Create a UINavigationBar Category with a custom sizeThatFits.

@implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size  
{
  CGSize newSize = CGSizeMake(self.frame.size.width,70);
  return newSize;
}
@end
查看更多
别忘想泡老子
3楼-- · 2019-04-30 06:09

As iAnurag post ans is correct but still have some ui problem (Width is not proper)


You can change size by adding category like below

Sample Project
Download

Code

#import "ViewController.h"
@implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
    CGRect rec = self.frame;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    rec.size.width = screenRect.size.width;
    rec.size.height = 70;
    return rec.size;
}
@end

Output
enter image description here
When press on "Button" enter image description here


Problem in iAnurag Code
enter image description here

查看更多
smile是对你的礼貌
4楼-- · 2019-04-30 06:19

https://developer.apple.com/library/prerelease/content/samplecode/NavBar/Introduction/Intro.html

From ReadMe.md:

Extended Navigation Bar #### This example demonstrates placing a custom view underneath the navigation bar in such a manner that view

appears to be part of the navigation bar itself. This technique may be used to create an interface similar to the iOS Calendar app.

My not humble opinion: Don't override sizeThatFits(_:), don't set constraints on nav bar height. Just do the illusion from example above.

查看更多
登录 后发表回答