我需要从AppDelegate更改UINavigationBar后退栏按钮文本,以将更改应用到我的应用程序中的所有视图.
我使用以下方法更改了标题字体样式:
UINavigationBar.appearance().titleTextAttributes = [ NSFontAttributeName: UIFont(name: "MyCustomFont",size: 20)! ]
但我不知道如何访问左侧栏按钮对其进行更改.
解决方法
斯威夫特3.0,4.0
只需通过UINavigationItem的扩展即可实现它.根据许多搜索,无法使用app delegate更改左按钮文本.
extension UINavigationItem{ override open func awakeFromNib() { super.awakeFromNib() let backItem = UIBarButtonItem() backItem.title = "Hello" if let font = UIFont(name: "Copperplate-Light",size: 32){ backItem.setTitleTextAttributes([NSFontAttributeName:font],for: .normal) }else{ print("Font Not available") } /*Changing color*/ backItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.green],for: .normal) self.backBarButtonItem = backItem } }
更新:
您可以在didFinishLaunchingWithOptions上更改AppDelegate的后退按钮箭头颜色,
/*It will change back arrow color only if you use backItem.setTitleTextAttributes,else it will change whole text color*/ UINavigationBar.appearance().tintColor = UIColor.orange
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。