我有一個簡單的應用程序與導航欄控制器,我想改變其導航欄,同時重寫drawRect函數。我在這裏讀過很多地方,我需要做的只是將代碼粘貼到我的appDelegate上方。可悲的是,它似乎沒有爲我做任何事情。我嘗試着將導航欄的顏色改爲一開始,然後再嘗試向其添加圖像,但是再次沒有任何反應。缺少什麼我在這裏重寫UINavigationBar drawRect函數不工作
我累插入此代碼的AppDelegate以上:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor redColor];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents([color CGColor]));
CGContextFillRect(context, rect);
}
@end
並與背景圖像:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
// Drawing code
UIImage *img = [UIImage imageNamed: @"13.png"];
[img drawInRect:CGRectMake(0, 0, 320, self.frame.size.height)];
}
@end
感謝您的幫助!
試着看看這個答案:http://stackoverflow.com/questions/7657465/uinavigationbars-drawrect-is-not-called-in-ios-5-0 –