想在导航栏的后退按钮项上使用自己的自定义字体,这过去对我有用:
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上,这对我来说已停止工作。有解决方法吗?
答案 0 :(得分:13)
您将要研究iOS 13中新的UINavigationBarAppearance
类。
在您的情况下:
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