ios - iOS 13 UIBarButtonItem 字体
问题描述
想要在导航栏后退按钮项目上拥有自己的自定义字体,这在过去对我有用:
let barButtonAttributes = [NSAttributedString.Key.foregroundColor : UIColor.pink,
NSAttributedString.Key.font : UIFont(name: "My-Awesome-Font", size: 18)!]
UIBarButtonItem.appearance().setTitleTextAttributes(barButtonAttributes, for: .normal)
UIBarButtonItem.appearance().setTitleTextAttributes(barButtonAttributes, for: .highlighted)
在 iOS 13 中,这对我不起作用。有解决办法吗?
解决方案
您需要了解UINavigationBarAppearance
iOS 13 中的新类。
在你的情况下:
let style = UINavigationBarAppearance()
style.buttonAppearance.normal.titleTextAttributes = [.font: #YOURFONT#]
style.doneButtonAppearance.normal.titleTextAttributes = [.font: #YOURFONT#]
navigationController?.navigationBar.standardAppearance = style
// You may want these as well:
navigationController?.navigationBar.scrollEdgeAppearance = ...
navigationController?.navigationBar.compactAppearance = ...
编辑: 文档 - https://developer.apple.com/documentation/uikit/uinavigationbarappearance
推荐阅读
- excel - Excel VBA图表 - 如果包含“括号”,将图表的标签设置为红色?
- objective-c - 请求关联构建器开始收集时的授权错误
- c# - 我可以在 xaml 代码中禁用 WPF 组合框的第一项吗?
- c# - 如何查看数据集函数的性能利用率
- python - 如何在不使用 reverse=True 参数的情况下以相反的顺序对字符串列表进行排序?
- javascript - 将 YES/NO 转换为 true/false 的更优雅的方法
- javascript - 从快捷方式更改异步 n 承诺
- javascript - 如何对从 AJAX 调用返回的数据进行分组?
- bash - 如何使用 bash 脚本将一个文件内容粘贴到不同的文件中?
- python - 熊猫 - 单列问题内的划分