我尝试更改navigationBar标题的颜色并尝试以下操作:
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.barTintColor = UIColor.red
navigationBarAppearace.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
navigationBarAppearace.tintColor = UIColor.white
一切正常,但标题的颜色没有改变。它仍然是黑色的。我以为这行会改变它
navigationBarAppearace.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
这是错吗?
答案 0 :(得分:1)
在您的控制器中尝试一下,您必须为大而普通的标题设置一次颜色。
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.red]
navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.red]