2016-03-04 100 views
0
override func viewDidLoad() 
{ 
    super.viewDidLoad() 
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1.0) 
    let attr: NSMutableDictionary! = [NSForegroundColorAttributeName: UIColor.whiteColor()] 
    UINavigationBar.appearance().titleTextAttributes = attr 
    self.view.backgroundColor = UIColor.whiteColor() 
} 

據說無法更改導航欄標題的文本顏色

'Cannot assign value of type 'NSMutableDictionary!' to type '[String : AnyObject]?'' 
在這條線

UINavigationBar.appearance().titleTextAttributes = attire 

,如果我將其更改爲

UINavigationBar.appearance().titleTextAttributes = attr as! [String: AnyObject] 

雖然沒有錯誤,但它可以改變文本的顏色。爲什麼?

回答

0

試試這個:

self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.redColor()] 
+0

請詳細說明該代碼如何回答問題。 – JAL

3

您可以在一般的更改標題文本導航欄的顏色,爲應用程序。 只需在您的AppDelegate.swift中加入didFinishLaunchingWithOptions函數。

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] 
+0

Hi @ postman99如果這個或任何答案已經解決了你的問題,請點擊複選標記,考慮[接受它](http://meta.stackexchange.com/q/5234/179419)。這向更廣泛的社區表明,您已經找到了解決方案,併爲答覆者和您自己提供了一些聲譽。沒有義務這樣做。 –