To change the back button text of the current view, add the following code to your viewDidAppear
:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let backBarBtnItem = UIBarButtonItem()
backBarBtnItem.title = "Different Text!"
navigationController?.navigationBar.backItem?.backBarButtonItem = backBarBtnItem
}
This is what it will look like:
If you would like to change the navigation back button title in the previous view controller, use this code in your viewDidLoad()
:
override func viewDidLoad() {
super.viewDidLoad()
let backBarBtnItem = UIBarButtonItem()
backBarBtnItem.title = "something different"
navigationItem.backBarButtonItem = backBarBtnItem
}
You can also just set the title of the previous view controller and iOS will automatically set that to the back button of the view controller.
For example, we can set our title
to be “awesome view controller”:
override func viewDidLoad() {
super.viewDidLoad()
title = "nice!"
navigationController?.pushViewController(AnotherViewController(), animated: true)
}
Now on the next view controller that push on the navigation stack, it will have this title as its back button.
The Complete iOS App Development Bootcamp
Disclosure: This website may contain affiliate links, meaning when you click the links and make a purchase, we receive a commission.