我正在尝试更改 UINavigationItem
的 font
属性。
我试过使用 titleTextAttributes
但不知何故我只能更改标题字体。
如何更改字体或 UINavigationItem ?例如,返回 UIButton
的“更多”文本如下所示:
我试过使用:
self.navigationController?.navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName: UIColor.blackColor(),
NSFontAttributeName: UIFont(name: "Papyrus", size: 18)!
]
但它只会改变图片上显示的内容,不会改变“更多”按钮的字体。
最佳答案
你的方法不起作用的原因是因为你只是在使用 titleTextAttributes = ...
当你必须使用 setTitleTextAttributes:forState:
我用这个函数来为我的整个项目全局自定义导航栏:
func customizeNavBar(_ color: UIColor, titleFont: UIFont, buttonFont: UIFont) {
UINavigationBar.appearance().tintColor = color
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: color, NSFontAttributeName: titleFont]
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: color, NSFontAttributeName: buttonFont], forState: UIControlState.Normal)
}
对于单个实例,调用相同的函数:
someBarButton.tintColor.setTitleTextAttributes([NSForegroundColorAttributeName: color, NSFontAttributeName: buttonFont], forState: UIControlState.Normal)
关于ios - 如何更改 UINavigationItem 字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28795735/