无法同时更改导航栏文本字体和颜色

时间:2015-08-07 08:57:37

标签: ios swift uinavigationcontroller uinavigationbar

我正在尝试同时更改文本字体和颜色,但不幸的是只有其中一个更改。请问我的问题在哪里?

    self.title = "Hello Members"

    if let font = UIFont(name: "Avenir-Body", size: 15) {
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orangeColor()]
        self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: font]
    }

1 个答案:

答案 0 :(得分:1)

试试这个:

   var attributes = [
    NSForegroundColorAttributeName: UIColor.greenColor(),
    NSFontAttributeName: UIFont(name: "Avenir", size: 30)!
    ]

    self.navigationController?.navigationBar.titleTextAttributes = attributes