2

This is the back icon and back text now:

But if I want my navigation back like this:

I have tried to set the back to my want icon image:

But it useless.

s-n-2
  • 405
  • 1
  • 6
  • 24

2 Answers2

7

You can hide back button text in many ways.Try this simple approach.

Step1: Goto your mainstoryBoard and click navigationBar.

Step 2: Goto Attributes Inspector under Navigation Item add a BLANK SPACE in Back Button

enter image description here

Step 3: If you want to change backButton text method is pretty much the same.

enter image description here

Update 1: If you want to use an image as a back button check this link


Update 2:

Method 2: Using custom image as a back button.

Paste below code into your detailVC and set image for your back Button.

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

   title = "Detail VC"

    let customButton = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(backButtonTapped)) //
    self.navigationItem.leftBarButtonItem  = customButton  
}

func backButtonTapped() {     
   _ = navigationController?.popToRootViewController(animated: true)  
}

I am setting back button image in assets catalogue with the 32pixel size.I am not sure about the asset image size.Check with apple doc about the size class.

enter image description here

Output:

enter image description here

Community
  • 1
  • 1
Joe
  • 8,868
  • 8
  • 37
  • 59
0

Create a new UIBarButton and add it the navigationItem.leftBarButton.

let backButton = UIBarButtonItem(image: UIImage(named:"yourImage"), style: .plain, target: self, action: #selector(yourBackMethod(sender:))
navigationItem.leftBarButtonItem = = backButton


@objc internal func yourBackMethod(sender: AnyObject) {
  navigationController.popViewController()
}

Hope this helps.

Srikanth Adavalli
  • 665
  • 1
  • 10
  • 25
dmlebron
  • 861
  • 6
  • 16