2013-10-25 34 views
10

我想改變iOS 7中後退按鈕的顏色。現在有沒有辦法將整個應用程序中的所有導航項更改爲特定顏色?這就是我在一個視圖控制器截至目前:在整個應用程序中更改導航項目的顏色?

self.editButtonItem.tintColor = [UIColor whiteColor]; 
    self.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor]; 
    self.navigationController.navigationBarHidden = NO; 
    self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 
    self.navigationController.navigationBar.translucent = NO; 
    self.title = @"Inbox"; 
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; 
+1

我已經回答了類似的問題: http://stackoverflow.com/questions/18929864 /如何-DO-I-變化的導航條,顏色在-IOS-18934411分之7#18934411 – RFG

回答

28

UINavigationItem不是一個視圖,它沒有顏色。

你,而不是想改變UIBarButtonItem色調的顏色。

使用UIAppearance代理,你可以做

[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]]; 

這將改變每個UIBarButtonItemtintColor在應用程序中。

您可以使用相同的策略來改變UINavigationBarbarTintColortitleTextAttributes

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // this will change the back button tint 
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]]; 
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; 

不幸的是there's no way of changing the translucent property using the proxy,所以你將不得不這樣做的每個欄上。

+0

迷死人,這基本上是我在問,但這個完美的作品。謝謝! –

+0

歡迎您,並記住這只是iOS 7兼容。 –

+0

嗯......它改變了除

0

從iOS7開始,你可以爲所有的導航項tintcolor只是爲了保持一致的外觀和感覺遍佈應用:

if ([self.window respondsToSelector:@selector(setTintColor:)]) { 
     self.window.tintColor = [UIColor redColor]; 
} 

另外,也要看看我的答案這裏推薦閱讀和觀看材料: StatusBar bug in iOS7?

+0

我認爲用戶詢問'UINavigationBar'和'UIBarButtonItem',你的回答適用於超過他的要求。 – Roland

0

superViewDidLoad方法中。

self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 

它會改變導航項目顏色的顏色。 按鈕也會發生同樣的情況。

+0

這個問題是關於整個應用程序。 – DanSkeel

0

這適用於改變後退按鈕顏色:

[[UINavigationBar appearance] setTintColor:[UIColor redColor]]; 

測試與iOS 9.3,iPhone和iPad。您的導航欄標題仍將使用默認顏色進行着色。這有點令人困惑。

1

斯威夫特答案

UINavigationBar.appearance().backgroundColor = UIColor.blackColor() 
UINavigationBar.appearance().barTintColor = UIColor.blackColor() 
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] 
UINavigationBar.appearance().tintColor = UIColor.blackColor() 
UIBarButtonItem.appearance().tintColor = UIColor.blackColor() 
UITabBar.appearance().backgroundColor = UIColor.blackColor() 
UITabBar.appearance().tintColor = UIColor.blackColor() 
UITabBar.appearance().unselectedItemTintColor = UIColor.darkGrayColor() 

把它放在你的AppDelegate的FUNC應用程序(應用程序:UIApplication的,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

相關問題