我想重寫UINavigationBar,然後添加一個自定義圖片,我添加到了AppDelegate文件和執行文件中,但是沒有用。
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"redbar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
IOS5及以後的版本:
if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) {
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"redbar.png"]
forBarMetrics:UIBarMetricsDefault];
}