Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - Remove a title from backBarButtonItem, but keep the arrow [duplicate]

Tags:

ios

swift

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

like image 731
Stevik Avatar asked Feb 23 '16 15:02

Stevik


2 Answers

Set the title text to an empty string.

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

Edit: As per comments below this will only work if you set the back button before you segue to the view controller with the button in it.

like image 182
yesthisisjoe Avatar answered Oct 21 '22 11:10

yesthisisjoe


If you do not need the title, do this in viewDidLoad of your previous ViewController

title = ""

If you need the title for first ViewController, toggle setTitle between viewWillAppear and viewWillDisAppear of previous viewController will do.

like image 42
Warif Akhand Rishi Avatar answered Oct 21 '22 12:10

Warif Akhand Rishi