0

Seemingly the accepted way of changing the back button text for a UIViewController's navigation bar is this answer, essentially setting the text to nothing on the previous view controller.

However, this has to be done on every view controller. Worse yet, the button still takes up quite a bit of horizontal space (past what you would logically expect) as if there's still text there.

Is there a way, say in a UINavigationController subclass to hide the back button text in every view controller and make the area occupied by the back button more or less just the size of the "<"?

Community
  • 1
  • 1
Doug Smith
  • 29,668
  • 57
  • 204
  • 388

1 Answers1

1

Create a subclass of UINavigationBar. In your subclass, override backItem to return a UINavigationItem with an empty title. You might have to use a string containing a space rather than the empty string.

Specify that subclass as the custom class of the navigation bar in your storyboard, or (if you create the navigation controller in code) using initWithNavigationBarClass:toolbarClass:.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Would this solve the issue of the back bar button occupying far more space than it should? It seems like even with `""` set as the text, it still takes up as much space as if there was two or three characters in the title. – Doug Smith Nov 04 '15 at 05:37
  • Apple specifies a minimum button touchable area of 44 x 44. I would assume this has something to do with that. – Sethmr Jun 02 '17 at 18:43