我使用Xcode 4.3.2并根据" Master-Detail Application"创建一个空项目。模板。 当我尝试通过下面的代码更改默认导航栏的外观时,没有任何反应,从不调用drawRect函数。
#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
...
我知道在iOS 5.x中,用户可以通过更简单的方式更改UI的外观,例如
[[UINavigationBar appearance] setBackgroundImage:img
forBarMetrics:UIBarMetricsDefault];
但我只是想知道为什么没有调用drawRect,任何人都可以解释?