Fix: Custom Back Button Image and Text in UINavigationBar (UIKit)

Fix: Custom Back Button Image and Text in UINavigationBar (UIKit)

Written by

in

Quick answer: Set navigationBar.backIndicatorImage and backIndicatorTransitionMaskImage on the source view controller’s navigation controller. Use navigationItem.backBarButtonItem with an empty title to hide the default “Back” text, then set navigationItem.backButtonTitle (iOS 14+) or the source VC’s title for custom text.

Why this happens

The default back button in a UINavigationController shows the previous view controller’s title (or “Back” if there isn’t one) with a standard chevron image. When you try to customize it by creating a UIBarButtonItem with both an image and title, the image either replaces the title entirely or stretches as a background — because UIBarButtonItem doesn’t support side-by-side image and text layout out of the box.

Apple’s intended API for this is the pair of properties on UINavigationBar: backIndicatorImage (the chevron/graphic) and backIndicatorTransitionMaskImage (the mask used during the push/pop transition animation). The title comes from the source view controller — the one that pushes the new view controller — not the destination.

How to fix it

1. Configure the navigation bar appearance in the source view controller

Place this code in the view controller that pushes the next screen (e.g., in viewDidLoad or viewWillAppear):

import UIKit

class SourceViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        setupCustomBackButton()
    }

    private func setupCustomBackButton() {
        guard let navigationBar = navigationController?.navigationBar else { return }

        // 1. Provide your custom chevron/arrow image
        let backImage = UIImage(named: "icon-back")
            ?.withRenderingMode(.alwaysOriginal) // preserve original colors

        navigationBar.backIndicatorImage = backImage
        navigationBar.backIndicatorTransitionMaskImage = backImage

        // 2. Customize the back button title
        // iOS 14+: use backButtonTitle on the navigation item
        navigationItem.backButtonTitle = "Custom"

        // iOS 13 and earlier: use backBarButtonItem with empty title
        // navigationItem.backBarButtonItem = UIBarButtonItem(
        //     title: "Custom",
        //     style: .plain,
        //     target: nil,
        //     action: nil
        // )
    }
}

Key points:
– Call this on the pushing view controller, not the pushed one.
– Use .withRenderingMode(.alwaysOriginal) if your image has multiple colors; otherwise it will be tinted.
– The backIndicatorTransitionMaskImage should match backIndicatorImage for a smooth transition animation.

2. Alternative: Global appearance via UINavigationBarAppearance (iOS 13+)

If you want the same custom back indicator across your entire app, configure it once in your app delegate or a base navigation controller:

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .systemBackground

    let backImage = UIImage(named: "icon-back")?.withRenderingMode(.alwaysOriginal)
    appearance.setBackIndicatorImage(backImage, transitionMaskImage: backImage)

    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
    UINavigationBar.appearance().compactAppearance = appearance

    return true
}

Then in each source view controller, only set the title:

navigationItem.backButtonTitle = "Custom" // iOS 14+
// or
navigationItem.backBarButtonItem = UIBarButtonItem(title: "Custom", style: .plain, target: nil, action: nil)

3. Hide the title entirely (icon-only back button)

If you only want the custom image with no text:

navigationItem.backButtonTitle = "" // iOS 14+
// or
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

The empty title tells the navigation bar to show just the indicator image.

How to prevent it

  • Always customize in the source VC — the view controller that initiates the push. Changes made in the destination VC are ignored.
  • Use vector assets (PDF) or properly sized PNGs (@1x, @2x, @3x) so the indicator stays sharp on all devices.
  • Test with long titles — the back button truncates automatically, but very long custom titles may look cramped.
  • Prefer backButtonTitle (iOS 14+) over backBarButtonItem for cleaner, more readable code.
  • Avoid UIBarButtonItem(customView:) for the back button — it breaks the interactive pop gesture and transition animations.

FAQ

Why does my custom back button work on the first push but not on subsequent pushes?

Because the back button belongs to the source view controller of each push. If you push A → B → C, the back button on C is configured in B, and the back button on B is configured in A. You must set the custom indicator and title in every view controller that can push another.

Can I use a different back button image for a specific view controller only?

Yes. Set navigationController?.navigationBar.backIndicatorImage and backIndicatorTransitionMaskImage in that specific source view controller’s viewWillAppear. The navigation bar updates its appearance when the view controller appears. Remember to reset it in viewWillDisappear if other screens should use the default.

The back button shows the previous screen’s title instead of my custom title. What’s wrong?

You’re likely setting the title on the destination view controller. The back button title is derived from the source view controller’s navigationItem.backButtonTitle (iOS 14+) or navigationItem.backBarButtonItem.title. Move the title configuration to the view controller that performs the push.


Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.