-2

When you create a navigation controller in the storyboard and create a segue to another view controller you automatically get this back button with an arrow and the title of previous page. (see image)

Image of problem

How can I delete the text and still have the arrow there? or How can I replace with my own image?

Thanks!

2 Answers2

6

Inside your viewDidLoad of the setting you can use this to change the title

let backButton = UIBarButtonItem()
backButton.title = "" //in your case it will be empty or you can put the title of your choice
self.navigationController?.navigationBar.topItem?.backBarButtonItem = backButton

and this to set your own image

let backImage = UIImage(named: "backButton")
self.navigationController?.navigationBar.backIndicatorImage = backImage
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = backImage
Do2
  • 1,751
  • 1
  • 16
  • 28
2

You can implement UINavigationControllerDelegate like this:

 func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        let item = UIBarButtonItem(title: " ", style: .plain, target: nil, action: nil)
        viewController.navigationItem.backBarButtonItem = item
    }

it affects next pushed controller backBarButtonItemtitle.

edit: in your ViewController

    class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource,UINavigationControllerDelegate  {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.delegate = self
    }
Govind Kumawat
  • 1,562
  • 1
  • 10
  • 17