1

So I'm building an iOS application, and I customized my UINavigationBar to be taller than the default size. A couple problems have arisen, however.

  1. My content acts as if the UINavigationBar is of the default height. This results in any views at y=0 to actually be hidden, or partially hidden, by my taller UINavigationBar. I have to manually place views the correct offset downward, which isn't a terribly huge issue, but I'm curious as to whether anyone has found a way to fix this. Essentially my UINavigationBar is being treated as a normal one with a larger background image.

  2. Any views/buttons in my UINavigationBar are not tappable if the portion being tapped is below the typical 44px bottom of a normal UINavigationBar. Anything within the normal range works fine, but below that 44px mark it doesn't register. Again, it's as if my UINavigationBar is being treated by the application as one with a normal height but a large background image. This is a much more critical issue that I really need to resolve.

Here is the code that modifies my UINavigationBar:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navBarBackground_iPhone.png"] forBarMetrics:UIBarMetricsDefault];
[self.navController.navigationBar setBackgroundColor:[UIColor whiteColor]];
[self.navController.navigationBar setFrame:CGRectMake(0, 0, self.frame.size.width, 72)];

This is performed in my main window's -makeKeyAndVisible after my UINavigationController is allocated and initialized with a root view controller. The background image is 320px wide and 72px tall (double for the @2x version).

As you can see, I attempt to set the UINavigationBar's height here, after this portion of code it doesn't seem to stick. It reverts to 44px.

I've tried unsuccessfully to subclass UINavigationBar. Any help is greatly appreciated.

Justin Ling
  • 690
  • 1
  • 8
  • 16
  • Sounds complex. Although you might want to consider _why_ you're changing the height, since sticking to UI that's familiar to the user is typically best. – Patrick Feb 08 '13 at 16:47
  • 1
    Helpful posts: http://stackoverflow.com/questions/8726006/custom-uinavigationbar-with-custom-height-causes-the-uibarbuttonitems-to-be-pos, http://stackoverflow.com/questions/2133257/iphone-how-set-uinavigationbar-height. – petert Feb 08 '13 at 17:00
  • @petert The top answer in your second link worked great! It solved both of my problems. Thanks! – Justin Ling Feb 09 '13 at 10:23

2 Answers2

0

Try to subclass UINavigationBar and override the following method:

 - (void)drawRect:(CGRect)rect
 {
    int heightYouWant = 100;

    UIImage *image = [UIImage imageNamed:@"title_bar_bg.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, heightYouWant)];

    self.tintColor = [UIColor colorWithRed:1/255.0 green:62/255.0 blue:130/255.0 alpha:1];
}
Jeepston
  • 1,361
  • 7
  • 7
Sergio Andreotti
  • 913
  • 2
  • 8
  • 26
  • Unfortunately this didn't work for me. It changes the background image but has no effect on either the height of the UINavigationBar nor the positioning of the root ViewController. – Justin Ling Feb 09 '13 at 06:21
0

Add this method to your subclass of UINavigationBar:

- (void)layoutSubviews {
    [super layoutSubviews];
    CGRect barFrame = self.frame;
    barFrame.size.height = heightYouWant;
    self.frame = barFrame;
}
Jeepston
  • 1,361
  • 7
  • 7
  • This does change the height of the UINavigationBar so that the background image is now properly showing. However, again it doesn't seem to affect how views act in relation to the UINavigationBar. I need to manually set the y-origin of views to the amount my UINavigationBar is taller than a default 44px one just to make it appear to be at y=0. – Justin Ling Feb 11 '13 at 08:43