Swift - remove title from backBarButtonItem but keep arrow

How to remove the title from the back button in the navigation bar, but I want to keep the arrow.

+5
source share
2 answers

Set the title text to an empty string.

navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil) 

Edit: According to the comments below, this will only work if you set the back button before you go to the view controller using the button in it.

+8
source

If you don't need a title, do it in the viewDidLoad your previous ViewController

 title = "" 

If you need a title for the first ViewController , then setTitle will switch between viewWillAppear and viewWillDisAppear previous ViewController .

+3
source

Source: https://habr.com/ru/post/1243685/


All Articles