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)

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...