UINavigationBar 上的自定义字体不起作用
Custom font on UINavigationBar not working
我不知道为什么这不起作用,我已经用许多有效字符串尝试过(顺便说一句,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)
}
我不知道为什么这不起作用,我已经用许多有效字符串尝试过(顺便说一句,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)
}