iOS
navigation controller
back button
Swift
app development

How to set back button text in iOS navigation controller?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In a UINavigationController, the back button shown on screen is configured by the previous view controller in the navigation stack, not the one currently being displayed. That detail explains why setting the title on the pushed screen often appears to do nothing.

To customize the back button text, set the previous controller's navigation item before pushing the next screen. On newer iOS versions, you can also control whether text is shown at all with backButtonDisplayMode.

Once that ownership rule is clear, most back-button customization issues become much easier to reason about.

Set the Back Title on the Previous View Controller

Suppose FirstViewController pushes DetailViewController. The back button visible in DetailViewController comes from FirstViewController.

swift
1class FirstViewController: UIViewController {
2    override func viewDidLoad() {
3        super.viewDidLoad()
4        title = "Home"
5
6        navigationItem.backButtonTitle = "Back"
7    }
8
9    func openDetails() {
10        let detail = DetailViewController()
11        navigationController?.pushViewController(detail, animated: true)
12    }
13}

That is the simplest modern API for changing the text while keeping the standard back-button behavior and swipe-to-go-back gesture.

Use backBarButtonItem for Older Patterns

Another common approach is assigning a UIBarButtonItem:

swift
1class FirstViewController: UIViewController {
2    override func viewDidLoad() {
3        super.viewDidLoad()
4
5        navigationItem.backBarButtonItem = UIBarButtonItem(
6            title: "Back",
7            style: .plain,
8            target: nil,
9            action: nil
10        )
11    }
12}

This still belongs on the previous controller. The target and action are usually nil because the navigation controller handles the back action automatically.

Remove or Minimize Back Text

If you do not want a long title to appear in the back button, iOS offers a cleaner option than manually forcing empty strings:

swift
1override func viewDidLoad() {
2    super.viewDidLoad()
3    navigationItem.backButtonDisplayMode = .minimal
4}

That keeps the standard arrow while minimizing the text presentation. It is often the best choice when screen titles are long and you care about space in the navigation bar.

Apply a Global Appearance Rule

If the same style should apply across the app, configure UINavigationBarAppearance once:

swift
1let appearance = UINavigationBarAppearance()
2appearance.configureWithDefaultBackground()
3
4let backAppearance = UIBarButtonItemAppearance()
5backAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.systemBlue]
6appearance.backButtonAppearance = backAppearance
7
8UINavigationBar.appearance().standardAppearance = appearance
9UINavigationBar.appearance().scrollEdgeAppearance = appearance

Appearance APIs are useful for styling, but per-screen back text is still usually set on the previous view controller's navigation item.

Keep the Default Navigation Behavior

Avoid replacing the back button with a custom left bar button item unless you really need custom behavior. A custom button can disable the default interactive pop gesture or require extra code to restore it.

If your goal is only to change the displayed text, prefer backButtonTitle or backBarButtonItem. They keep the standard navigation controller behavior intact.

That usually gives you the customization you want without paying the maintenance cost of reimplementing native navigation behavior.

Common Pitfalls

  • Setting the back button text on the destination view controller instead of the source view controller.
  • Replacing the back button entirely when a simple title change would have been enough.
  • Using an excessively long back title, which can truncate badly on smaller devices.
  • Forgetting that global appearance styling and per-screen back text are different concerns.
  • Removing the default back behavior and then losing the native swipe-back interaction.

Summary

  • The visible back button is configured by the previous view controller.
  • Use navigationItem.backButtonTitle for a simple text change.
  • 'backBarButtonItem is another valid option, especially in older codebases.'
  • Use backButtonDisplayMode = .minimal when you want little or no text.
  • Prefer built-in APIs so the standard navigation behavior stays intact.

Course illustration
Course illustration

All Rights Reserved.