Change UINavigationBar back button text and font from AppDelegate using Swift

Swift 3.0,4.0

Simply you can achieve it with extension of UINavigationItem. According to many search there is no way to change left button text with 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
    }

}

Update:

You can change Back Button arrow colour from AppDelegate on 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

To change the image color you can either use the font file and change the color or use the image with the color you needed.

let yourBackButtonIcon = //YourImage here
let navigationBar = UINavigationBar.appearance()
navigationBar.backIndicatorImage = yourBackButtonIcon
navigationBar.backIndicatorTransitionMaskImage = yourBackButtonIcon

To change the back button title text color

navigationBar.titleTextAttributes = [NSFontAttributeName: yourFont,
NSForegroundColorAttributeName: yourColor]

Note:-

Above code should be inside the AppDelegate class of applicationDidFinishLaunching method

Tags:

Ios

Swift