0

i am facing a new problem.

I have custom navigation controller in my application. I have to add an image to navigationbar and i used this code in my AppDelegate-

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

This code is working fine for me, but when i use MFMailComposer in my application and call it on a button event i see that the navigationbar of MFMailcomposer is also changed to my custom navigationbar which i don't want to change.

Any Ideas!!!

iphonedev23
  • 991
  • 2
  • 12
  • 24

1 Answers1

3

By adding a category to the UINavigationBar, you are adding a method to all instances of UINavigationBar.

Since you are overriding drawRect: that means that whenever any navigation bar wants to draw itself it is using your method rather than the standard drawRect:

Rather than do this, you should just add the image to your navigation bars where you want them , rather than change it globally as you have done here.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • In this case i am facing another issue. I added image to UINavigation bar and I also added UINavigationBar buttons but after adding image buttons are not visible :( – iphonedev23 Dec 30 '11 at 04:20
  • 1
    Maybe the image is being drawn *above* the buttons, which is why they are not visible. – Abizern Dec 30 '11 at 10:00
  • The sequence of adding navigation images and buttons is first i am adding image to navigation bar and then adding buttons to navigation bar. Please suggest how to solve this issue. – iphonedev23 Jan 02 '12 at 04:12