6

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

Mark Gaensicke
  • 504
  • 5
  • 16

3 Answers3

5

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
Jageen
  • 6,345
  • 2
  • 37
  • 56
  • Note: My Code is tested on iOS8 devices – Jageen Dec 06 '14 at 06:14
  • 2
    Dude, your downloaded build is working fine on xcode 6 with ios 8 iphone 6 simulator. – Ashish P. Dec 06 '14 at 07:53
  • project downloaded from your given link is working fine as per my answer. – iAnurag Dec 06 '14 at 07:54
  • @iAnurag i did not add your code, if i add ur code there will ber problem (width is not proper) – Jageen Dec 06 '14 at 08:07
  • @AshishP. thanks for confirmation, Waiting for Mark to confirm on his environment. – Jageen Dec 06 '14 at 08:10
  • The proposed solution works, but is very hackish. You both, however, bought me to the idea of making a subclass of UINavigationBar along with a UINavigationController that is initialized with this class for navigation bars. – Mark Gaensicke Dec 06 '14 at 10:27
  • Idea is not hacki please link i gave and select which ever is best sub classing or category (http://stackoverflow.com/questions/8060884/when-to-use-categories-and-when-to-use-subclassing) – Jageen Dec 06 '14 at 10:29
4

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.

Stanislav Smida
  • 1,565
  • 17
  • 23
  • 1
    As you point out, the example code is really just an illusion of an extended navigation bar. The bar is the same height, they just remove the shadow and add another view to the bottom of the nav bar. They also remove any translucency. Apple's example code is at best, a hack. – Jason Moore Jun 01 '17 at 19:22
0

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
iAnurag
  • 9,286
  • 3
  • 31
  • 48