1

I use Xcode 4.3.2 and create an empty project based on "Master-Detail Application" Template. When I try to change the default navigation bar's appearance by code below, nothing happened, the drawRect function is never called.

#import "AppDelegate.h"

@implementation UINavigationBar (UINavigationBarCustomDraw)

- (void)drawRect:(CGRect)rect
{
    NSLog(@"redraw");
    [[UIImage imageNamed:@"NavBar.png"] drawInRect:rect];
    self.topItem.titleView = [[UIView alloc] init];

    self.tintColor = [UIColor colorWithRed:0.6745098 green:0.6745098 blue:0.6745098 alpha:1.0];
 }

 @end

 @implementation AppDelegate
 ...  

I know in iOS 5.x user can change UI's appearance by more easier ways, like

[[UINavigationBar appearance] setBackgroundImage:img 
                                   forBarMetrics:UIBarMetricsDefault];

But I just wonder why drawRect is not called, anyone can explain?

Matt.Z
  • 602
  • 7
  • 19
  • 1
    possible duplicate of [UINavigationBar's drawRect is not called in iOS 5.0](http://stackoverflow.com/questions/7657465/uinavigationbars-drawrect-is-not-called-in-ios-5-0) - your answer is in there. It is explicitly not called in iOS5. – jrturton May 29 '12 at 12:57
  • Oh.. I found this thread with the same problem... http://stackoverflow.com/questions/7657465/uinavigationbars-drawrect-is-not-called-in-ios-5-0 – Matt.Z May 29 '12 at 13:02
  • Thanks jrturton... But I don't think this is a great way to prevent people from doing this, also I consider this will make a lot of people confused with the knowledge they already have. – Matt.Z May 29 '12 at 13:06

0 Answers0