2017-07-31 61 views
0

所以说我有3个视图控制器,A,B和C.如何为各个导航栏指定标题颜色? Swift

A有黑色背景,B是白色,C是蓝色。

所有这些使用NavigationControllerBars导航。

如何以编程方式更改navBar标题的颜色?

所以,我有一个白色的标题上A,黑色的B,也许红色的C.

例如从什么我已经收集大家使用:

navigationController?.navigationBar.titleTextAttributes = [NSForegroundAttributeName: UIColor.white] 

我是新来的很快,但对我来说,看起来像Obj-C?

这并不为我工作,我不断收到

替换 'NSForegroundColorAttributeName' 与 'NSForegroundColorAttributeName.rawValue'

为错误。

+1

了解如何使用NSAttributedString。 –

+2

[在Swift中使用NSMutableAttributedString更改特定文本的颜色](https://stackoverflow.com/questions/25207373/changing-specific-texts-color-using-nsmutableattributedstring-in-swift) –

回答

0

我在我的代码中使用了它,它编译时没有任何问题。

雨燕2.3

navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] 

斯威夫特3

navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]