无法更改 UINavigationBar 自定义字体颜色

Can't change UINavigationBar Custom Font Color

我正在使用 Storyboard,我想在我的一个 ViewController 上将 UINavigationBar 标题颜色更改为 UIColor.whiteColor()。 Xcode 正在识别字体,但我无法更改颜色。

我试过: 使用 Storyboard 和下面的代码更改它,但它似乎不起作用。我还尝试使用不同的字体,.otf 和 .ttf 认为这可能是由字体错误引起的。到目前为止,我只能使用任何自定义字体获得黑色。

 var nav = self.navigationController!.navigationBar
    self.navigationItem.title = "HOME"
    nav.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    nav.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Impact", size: 30)!]

我发现你需要像这样同时设置属性:

nav.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Impact", size: 30)!]

您还可以将导航栏的 tintColor 属性 设置为您想要的颜色。