How to increase the height of UINavigationBar?

人盡茶涼 提交于 2019-12-06 01:49:29

问题


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...

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


回答1:


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


When press on "Button"


Problem in iAnurag Code




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/27328136/how-to-increase-the-height-of-uinavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!