Swift and SwiftUI tutorials for Swift Developers

How to change the back button image and color in SwiftUI

The navigation view’s back button is usually set to blue by default and uses a chevron icon to indicate “Back.” However, with the UINavigationBarAppearance API, you can customize not only the color, but also the indicator image of the back button.

Let’s see how this customization works. To change the indicator image, you can call the setBackIndicatorImage method and provide your own UIImage. Here, I’ll set it to the system image arrow.turn.up.left

navBarAppearance.setBackIndicatorImage(UIImage(systemName: "arrow.turn.up.left"), transitionMaskImage: UIImage(systemName: "arrow.turn.up.left"))

For the color of the back button, you can change it by setting the tint property as in this example:

NavigationStack {
  .
  .
  .
}
.tint(.black)

In XCode we can see how the button has changed and also its color:

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Article

How to change font and color in a Navigation Bar in SwiftUI

Next Article

How to use NavigationLink in SwiftUI

Related Posts