Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backBarButtonItem in iOS (Swift)

Tags:

ios

swift

var backButton: UIBarButtonItem = UIBarButtonItem(title: "CUSTOM", style: UIBarButtonItemStyle.Bordered, target: self, action: nil)
    newNavigationItem.backBarButtonItem = backButton

Where is newNavigationItem: UINavigationItem

I want custom back title. It shows "Back" text or "Title of last view". So it does not work. Why?

like image 629
Max Avatar asked Jul 12 '14 13:07

Max


2 Answers

The method that Yogesh Suthar said will replace the whole back button, so you will not have the default left arrow sign! I suggest to use this code:

navigationController?.navigationBar.topItem?.backBarButtonItem = backButton
like image 152
Majid Avatar answered Sep 28 '22 14:09

Majid


Use leftBarButtomItem

newNavigationItem.backBarButtonItem = backButton

should be

newNavigationItem.leftBarButtonItem = backButton
like image 28
Yogesh Suthar Avatar answered Sep 28 '22 13:09

Yogesh Suthar