0

Since updating to Xcode 11.4 I'm running into the issue that I can't figure out how to change the color of the back arrow in the navigation bar.

Before I was able to simply use:

navigationBar.barTintColor = DisplayUtils.sweetGreenColor()

However, 11.4 has forced me to use the standardAppearance functionality to set the color of my navbar and everything. Which is no big deal, this works for setting the barTint and title colors:

navigationBar.standardAppearance.backgroundColor = DisplayUtils.sweetGreenColor()

let buttonAppearance = UIBarButtonItemAppearance()
buttonAppearance.normal.titleTextAttributes = [.foregroundColor : DisplayUtils.whiteColor()]
navigationBar.standardAppearance.buttonAppearance = buttonAppearance

navigationBar.standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: DisplayUtils.whiteColor(), NSAttributedString.Key.font: UIFont(name: "Roboto-Bold", size: 18) as Any]

I just don't see a property that replaced barTintColor on the UIBarButtonItemAppearance object. It lets you change the color of the text, change the image itself, but no color property.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Karl Barek
  • 83
  • 5

2 Answers2

0

I found a solution that works in my instance. It works because I'm creating my viewControllers in code such as:

if let stbrd = self.storyboard {
   if let vc: ViewController = stbrd.instantiateViewController(withIdentifier: "VC") as? ViewController {
                self.navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: .plain, target: nil, action: nil) // remove back button text
                self.navigationItem.backBarButtonItem?.tintColor = DisplayUtils.sweetGreenColor()
                self.navigationController?.pushViewController(vc, animated: true)
   }
}

It's the line:

self.navigationItem.backBarButtonItem?.tintColor = DisplayUtils.sweetGreenColor()

That properly sets the color of the back arrow on the newly presented view controller.

I still don't see how to simply set that color on the view controller itself like before this change. So, if anyone can offer up that knowledge it would be great.

Karl Barek
  • 83
  • 5
0

On the storyboard, for your Navigation Controller change the "Bar Tint" to its "Default" value, then on your code you can change it as you normally would.

By programmatically simply first change navigation bar color to default then you can update what you are already doing.

    if #available(iOS 13.0, *) {
        self.navigationController?.navigationBar.standardAppearance.configureWithDefaultBackground()
    }
halfer
  • 19,824
  • 17
  • 99
  • 186