0

覆盖UINavigationController用我自己的子类UINavigationBar的一个实例替换默认的navigationBar属性。所以我尝试了一些像最好覆盖navigationController的navigationBar属性

_navigationBar = [[SBNavigationBar alloc] init]; 

在我的-initWithRootViewController:。但是这并没有按照我的预期发挥作用。仍然显示默认的navigationBar

那么覆盖navigationBar的最佳点是什么?

在此先感谢
-f

+0

做我的回答帮助? – jd291 2010-06-10 10:38:00

回答

1

如果您查看文档http://developer.apple.com/iphone/library/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html,你会看到的导航栏属性是只读

要定制navigationBar,您可以使用类别为例。您将在stackoverflow找到许多回答此问题的问题。

一个简单的版本是把图像中的drawRect:是这样的...

@implementation UINavigationBar (Custom) 

- (void)drawRect:(CGRect)rect { 
    UIImage *image = [UIImage imageNamed: @"bg_toolbar.png"]; 
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 

@end 
+0

+1正确答案.... – Sabby 2011-09-03 11:09:14