1
votes

I created an application with a TabBarController, 4 TabBarItems and every TabBarItem have is own NavigationController file (everything created in IB).

I'm using the drawRect function to design my navigationBar:



@implementation UINavigationBar (customImage)

-(void)drawRect:(CGRect)rect {

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

}

@end

The problem is that the NavigationBar change for every ViewController inside my app, what I want is only draw the NavigationBar for one TabBarItem only and use the default navigationBar for other controller.
How to do that?

Thanks,

2

2 Answers

0
votes

Using a category is probably not the best idea in this case (if you override drawRect: using a category, all UINavigationControllers will be affected). You'd be better off subclassing UINavigationController, and using the custom subclass only in the tab that you want.

Edit: Subclassing UINavigationController is fairly easy:

(in the .h file)

@interface MyCustomNavigationController : UINavigationController {
}
@end

(in the .m file)

@implementation MyCustomNavigationController

-(void)drawRect:(CGRect)rect {
    //custom drawing here
}
@end

Then, use MyCustomNavigationController instead of UINavigationController in your code where appropriate. Categories (which you used in the sample) are good for adding convenience methods to existing classes, but can be dangerous when replacing already-existing methods (since your custom method will replace the original for all uses).

0
votes

Ok,

He take me a long time but I fins a solution. by using swizzling method I can do whatever I want. Look at this link for more information on how to implement it.