When I create a custom back button, I use the following code:
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithTitle:@\"Yeah\" style:UIBarButton
For Swift, using Erzekiel's answer as the basis for this, you can simplify it to -
extension UIViewController {
func setBackButtonTitle(to title: String) {
let barButtonItem = UIBarButtonItem(title: title, style: .plain, target: self, action: nil)
self.navigationItem.backBarButtonItem = barButtonItem
}
}
This should be called from the parent viewController, eg in viewWillDisappear -
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.setBackButtonTitle(to: "Back"))
}