ios – 如何更改UINavigationItem字体?

我正在尝试更改UINavigationItem的字体属性.

我尝试过使用titleTextAttributes但不知怎的,我只能更改标题字体.

如何更改字体或UINavigationItem?例如,Back 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,forState: UIControlState.normal)

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...