使用Swift从AppDelegate更改UINavigationBar后退按钮文本和字体

eif*_*cht 6 ios swift

我需要更改UINavigationBar后退栏按钮文本AppDelegate以将更改应用到Views我的应用程序中的所有内容.

我使用以下方法更改了标题字体样式:

UINavigationBar.appearance().titleTextAttributes = [
            NSFontAttributeName: UIFont(name: "MyCustomFont", size: 20)!
]
Run Code Online (Sandbox Code Playgroud)

但我不知道如何访问左侧栏按钮对其进行更改.

Raj*_*n S 9

斯威夫特3.0,4.0

只要你可以实现它extension的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
    }

}
Run Code Online (Sandbox Code Playgroud)

更新:

您可以从AppDelegate打开更改后退按钮箭头颜色didFinishLaunchingWithOptions,

 /*It will change back arrow color only if you use  backItem.setTitleTextAttributes, else it will change whole text color*/
 UINavigationBar.appearance().tintColor = UIColor.orange
Run Code Online (Sandbox Code Playgroud)