2009-12-02 127 views
0

我着色的橙色我的導航欄有:彩色化UINavigationBar的iPhone SDK

navigationController.navigationBar.tintColor =的UIColor colorWithRed:0.88綠0.52藍:0.27的α:1];

一切正常,每個按鈕都像酒吧一樣橙,但是當ic來到一個自定義的正確的項目菜單時,它顯示爲藍色。 這是截圖:http://img146.imageshack.us/img146/5605/schermata20091202a14565.png

,這是正確的按鈕的代碼:

UIView *container = [[UIView alloc] init]; 
UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 80, 45)]; 

NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2]; 

UIBarButtonItem *bi = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addGadget:)]; 
bi.style = UIBarButtonItemStyleBordered; 
[buttons addObject:bi]; 
[bi release]; 

bi = [[UIBarButtonItem alloc] 
initWithImage:[UIImage imageNamed:@"less.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(setEditing:)]; 
[buttons addObject:bi]; 
[bi release]; 

[tools setItems:buttons animated:NO]; 
[buttons release]; 

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
[tools release]; 

有人可以幫我解決這個問題? (我希望一切都是橙色的)

回答

1

您應該將UIToolbar對象的tintColor設置爲與UINavigationBar相同。

請注意,UIToolbarUINavigationBar不一樣,背景漸變/顏色有點不同。嘗試UIToolbar的backgroundColor設置爲+[UIColor clearColor]

而且,你可能甚至不需要容器UIView,因爲UIToolbarUIView子類,所以你可以只單獨使用它作爲customView。

+0

感謝您的回答。 如果它設置backgroundcolor清除,沒有任何變化。 如果我設置清除色調,它給了我一個黑色的一塊, ,如果我把它設置爲相同的橙色,它缺少一個黑色像素的底部,所以它不能很好地融入導航欄 – w4nderlust

+0

這就是我所說的。 tintColor應該是橙色的,沒錯。你不希望繪製背景(因爲它是不同的),所以我告訴你嘗試設置背景顏色來清除。這是行不通的,所以編寫一個'UIToolbar'子類並重寫-drawRect:並且什麼都不做,我認爲這足夠了。 – Joost

+0

好吧,它的工作很棒,非常感謝你! – w4nderlust