2017-06-29 82 views
2

我在iOS 11中使用新的擴大導航欄標題。但我似乎無法更改textColor。更改iOS 11大標題顏色

我試着這樣做:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; 

這並沒有做任何事情。有任何想法嗎?

+0

[PrefersLargeTitles]設置爲true時更改導航欄標題的文本顏色的可能副本(https://stackoverflow.com/questions/44619396/changing-the-text-color-of-a-導航欄 - 標題 - 當 - preferslargetitles-is-s) – Kqtr

+0

有用於在Xcode中的錯誤,但它現在工作。完整的工作代碼在這裏:https://stackoverflow.com/a/48598246/7698127(這裏沒有發佈答案,以避免重複的答案) – Kqtr

回答

11
self.navigationController.navigationBar.largeTitleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; 
+1

不適合我:( –

3

我認爲它還是在Xcode 9測試版中的錯誤6.

我發現不同的「解決方案」爲它:

  1. 這是可能的改變,如果你把標題的顏色這在AppDelegate中:
 
    if #available(iOS 11.0, *) { 
     UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue] 
    } 
  • 行吟[R方式是設置在控制器的viewDidLoad的顏色,但這個祕密,使其工作是設置字體也:
  •  
        if #available(iOS 11.0, *) {    
         self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 31, weight: UIFont.Weight.bold) ] 
        } 
    

    希望它可以幫助你。

    問候!

    +0

    如果#available(iOS 11.0,*)找不到! –

    +0

    你是否使用Xcode 9? –

    +0

    是的,任何Xcode 9解決方案? –