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