我不知道为什么这不起作用,我已经用许多有效的字符串尝试过(顺便说一下,cFont = "Courier"但我已经尝试过 "Chalkduster"和其他一些来测试),颜色正确以上是工作,但字体不是。有任何想法吗?
函数就在 AppDelegate 中的 didFinishLaunchingWithOptions 下面。
func setUpAppearance() {
//Work fine
window?.tintColor = Colors().navBackgroundColor
UINavigationBar.appearance().barTintColor = Colors().navBackgroundColor
UINavigationBar.appearance().tintColor = Colors().navTextColor
//Doesn't work
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: cFont, size: 24)!]
}
谢谢你的帮助
最佳答案
明白了!没有意识到我必须为栏按钮项以及 NSForeGroundColorAttributeName 添加一个单独的实例。
更新后的函数工作正常...
func setUpAppearance() {
window?.tintColor = Colors().navBackgroundColor
UINavigationBar.appearance().barTintColor = Colors().navBackgroundColor
UINavigationBar.appearance().tintColor = Colors().navTextColor
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: cFont, size: 24)!, NSForegroundColorAttributeName: Colors().navTextColor]
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: cFont, size: 24)!, NSForegroundColorAttributeName: Colors().navTextColor], forState: .Normal)
}
关于ios - UINavigationBar 上的自定义字体不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37445889/