0 Comments

Just stumbled over this one in a recent endeavour. The default behaviour of iOS is to use the title of the previous navigation controller as the text for the back button.

BackButtonNotSet

If you want a different text such as back you might find this recipe from Xamarin which works. But it does feel like a hack and it requires you to adopt this approach in every view.

Another approach is to set the NavigationItem.BackBarButtonItem attribute in the view controller:

NavigationItem.BackBarButtonItem = new UIBarButtonItem {Title = "Back"};

The set text will be displayed as the back button of the next view controller. In other words previous view controller always sets the back button text of the following.

BackButtonSet

If you are using a central point to generate your views e.g. a navigation service or factory you can apply this to every view you create. Which makes this approach a lot less error prone.

If you are using storyboards you have a further option. The title can be set directly in the designer under Navigation Item, Back Button.

Set back button title in Storyboard editor

Note this option is only available when you choose the (no longer recommended) push navigation for your segue.

Conclusion

In this post we saw how we can set the title of the back button. The title of the back button is always set in the preceding view controller.

Using a storyboard the title can be set directly in the storyboard designer.

You can find an entire little app sample on GitHub.

Post comment