2013-09-30 42 views
5

我想將導航欄的背景顏色更改爲純綠色。導航欄背景顏色 - 半透明不是

規則:我不能用的AppDelegate :)

我試過亂:

//It's green but it's translucent 
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]]; 

//It's white, first line has no effect 
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]]; 
[self.navigationController.navigationBar setTranslucent:NO]; 

//Same result as case 1 
[self.navigationController.navigationBar setAlpha:0.0f]; 
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]]; 

//Too dark 
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent]; 
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]]; 

//Only affects the back button's color: 
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]]; 

所以任何想法?

謝謝,沒有看到有barTintColor和TintColor。接受最早的答案。

+0

迪迪你用故事板?然後選擇視圖控制器,然後在模擬指標下的檢查器中將頂部欄設置爲不透明的導航欄 – thorb65

回答

17

使用此行代碼在你的viewController didLoad方法

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:29.0f/255.0f green:149.0f/255.0f blue:174.0f/255.0f alpha:1.0f] 
0

請使用下面的代碼可能會對你有幫助。

navController.navigationBar.barTintColor = [UIColor yourcolor]; 
+0

以上答案和我的答案有什麼不對? –

1

使用這一個,的導航欄的

self.navigationController.navigationBar.tintColor=[UIColor colorWithRed:19.0/255.0f green:52.0/255.0f blue:36.0/255.0f alpha:1];