2013-10-09 101 views
19

我已經開發了iOS7的應用程序,它具有這樣的設計如何改變後退按鈕顏色iOS7

enter image description here

正如你可以看到有一個藍色箭頭爲我所有的返回按鈕(使用的UINavigationController和塞格斯)我想讓他們的紅色,這是我的代碼:

[UIBarButtonItem appearance]setTintColor:(UIColorFromRGB(toolbarTintColor))]; 
[[UIBarButtonItem appearance]setTitleTextAttributes:textAtributesDictionaryNavBarButtons forState:UIControlStateNormal]; 

但結果只適用於所有其他的按鈕,任何幫助,我會感激

在此先感謝支持

回答

34

導航條的着色顏色屬性決定的iOS 7的欄按鈕項的文本的顏色你正在尋找的代碼是這樣的:

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

,當然,用任何你想要的顏色代替[UIColor redColor]

+0

簡單efective 100%的工作感謝隊友! = D –

+2

tintColor屬性沒有UI_APPEARANCE_SELECTOR,所以我認爲這個解決方案可能不可靠。恩里科Susatyo的答案似乎是正確的。 –

+0

不知何故,這在iOS 8(8.1)中適用於我,但不適用於iOS 7.只有文字顏色發生變化,而不是< 以前用於iOS 7中。嗯.. – Daniel

12

將這個代碼在App代表:

Objective-C的

[self.window setTintColor:[UIColor redColor]]; 

斯威夫特

self.window?.tintColor = UIColor.redColor() 
+1

這是一個更好的答案,因爲它建議自定義AppDelegate.m中的導航文本。 – Hahnemann

+0

適用於iOS 9.2.1。在Xcode 7.2中。 –

+0

但我不想更改我的標籤欄的文字顏色 – fujianjin6471

10

如果你不想改變色調顏色整個應用程序,只是想在一個導航欄上做到這一點,這樣做:

self.navigationController.navigationBar.tintColor = [UIColor redColor]; 
1

斯威夫特:

self.navigationController?.navigationBar.tintColor = UIColor.grayColor() 
4

如果你想迅速的版本。

UINavigationBar.appearance().tintColor = UIColor.whiteColor() 

另外,如果您想將此樣式應用於所有導航視圖控制器。把你的應用程序didFinishLaunchingWithOptions方法的代碼在你的AppDelegate

1
  • 如果你使用故事板,那麼你已經添加了類督察窗格下的keyPath「tintColor」用戶定義的屬性。
  • 由於在最新版本的「界面」構建器中刪除了靜態tintColor屬性。 click '+', add tintColor in KeyPath, set the Type color and add your color.
-2
-(void)viewDidAppear:(BOOL)animated 
{ 
    //set back button color 
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal]; 
    //set back button arrow color 
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; 
} 
相關問題