2016-03-04 86 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)。这向更广泛的社区表明,您已经找到了解决方案,并为答复者和您自己提供了一些声誉。没有义务这样做。 –