导航栏Swift中的文本颜色

时间:2014-09-26 11:58:46

标签: ios objective-c swift xcode uinavigationbar

我想在导航栏中显示白色文字,但只要我有白色字体代码,我仍然会将其设为黑色。

    let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    self.navigationController?.navigationBar.titleTextAttributes = titleDict
    self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 20)]

我试过

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

但没有工作

1 个答案:

答案 0 :(得分:7)

似乎每次设置titleTextAttributes时都要覆盖更改。尝试同时设置所有属性:

self.navigationController?.navigationBar.titleTextAttributes = [        
    NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 20),
    NSForegroundColorAttributeName: UIColor.whiteColor()
]