[英]Cannot change color of navigation bar title text
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]
雖然沒有錯誤,但是可以更改文本的顏色。 為什么?
通常,您可以為應用更改標題文本導航欄的顏色。 只需在didFinishLaunchingWithOptions函數中的AppDelegate.swift中添加它即可。
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
嘗試這個:
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.redColor()]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.