Search code examples
iphoneios4uinavigationcontrolleruinavigationbareventkit

Clear iPhone Navigation Bar Image


I am currently using this code in my App Delegate to set a custom background image for the Navigation bar:

@implementation UINavigationBar (CustomImage)
   - (void)drawRect:(CGRect)rect {
      UIImage *image = [UIImage imageNamed: @"MyNavigationBar.png"];
      [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
   }
@end   

It works great, and for all the views in my App I set the Navigation bar title to show no text (so it won't cover up the background image).

One of the views presents a modal view controller (an EKEventEditViewController to be exact), and the title in the Navigation bar says "Add Event", which shows up on top of my custom image.

I have tried several ways to change the title (to no avail), but would rather prevent the custom Navigation bar background image from showing up only in this modal view.

Does anyone know of a way to do this while still using the stated method for setting the Navigation bar background image?


Solution

  • please, never ever do this...

    You are replacing the drawRect: method in UINavigationBar, very brittle and likely to cause you (and your users) headaches.

    Your background will always show up in all instances of UINavigationBar because you have replaced the implementation of drawRect:

    There is no way to replace the title of the EKEventEditViewController. Of course there is always a way, but its even worse than replacing the implementation of drawRect:

    Instead, please make a subclass of UINavigationBar and use that in the places you require a custom nav bar.