ios – 如何更改UINavigationItem字体?

前端之家收集整理的这篇文章主要介绍了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)
原文链接:https://www.f2er.com/iOS/328734.html

猜你在找的iOS相关文章