NavigationBar Back Button Color iOS 16

I just noticed, that iOS 16 is using the accent color for the navigation bar back button. (SwiftUI) When running my app on iOS 15 devices it's white.

Is there a way to change that behavior? I want to have another accent color than white.

Post not yet marked as solved Up vote post of fbertuzzi Down vote post of fbertuzzi
8.6k views

Replies

You can set accentColor on the NavigationStack

  • Thank you for your reply! However I'm not using NavigationStacks since I need to support iOS 15 as well. Also when I change the accent color at the navigation level it changes everywhere. But I do want to have it different than white on some dialogues for example. Also this behavior is just happening when using iOS 16, on iOS 15 it looks like it's supposed to.

Add a Comment

You can try this:

  let appearance = UINavigationBarAppearance()

  appearance.configureWithOpaqueBackground() // configure
   

  let backItemAppearance = UIBarButtonItemAppearance()
  backItemAppearance.normal.titleTextAttributes = [.foregroundColor : UIColor.white] // fix text color
  appearance.backButtonAppearance = backItemAppearance
   
  let image = UIImage(systemName: "chevron.backward")?.withTintColor(.white, renderingMode: .alwaysOriginal) // fix indicator color
  appearance.setBackIndicatorImage(image, transitionMaskImage: image)
   
  UINavigationBar.appearance().tintColor = .white // probably not needed
   
  UINavigationBar.appearance().standardAppearance = appearance
  UINavigationBar.appearance().scrollEdgeAppearance = appearance
  UINavigationBar.appearance().compactAppearance = appearance
  UINavigationBar.appearance().compactScrollEdgeAppearance = appearance

  • Unfortunately this did not work in my project...any other suggestions are welcome!

  • This worked for me! But all I had to do was set the back indicator image (I didn't need to set the back button appearance).

Add a Comment

Sadly this method no longer works. It was working great in iOS 15 and below, but something must have changed.

In iOS 16 when you are using NavigationStack, you might use the .tint(YourColorHere):

NavigationStack {
// UI components here
}
.tint(YourColorHere)

UINavigationBar.appearance().barTintColor = UIColor(.black)