swiftback-buttonuinavigationitemtintcolor

Back Button Tint Color


How can I change the back button of a certain navigation controller. I have tried to use

override func viewDidLoad() {
    super.viewDidLoad()
    navigationItem.backBarButtonItem?.tintColor = UIColor.red
}

I know that if i use navigationController it will change the back button tint color on all of my view controllers.


Solution

  • Try this!!

    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            self.navigationController?.navigationBar.tintColor = .red
        }
        
        override func willMove(toParent parent: UIViewController?) {
            self.navigationController?.navigationBar.tintColor = // original color
        }
    }