1

enter image description here

Please take a look at my screenshot, the blue "Back" text always show on iphone plus (6s plus, 7 plus for both simulator and real device) . It does not show on smaller screen iphone. I tried lot of way to hide/change it from present/previous controller but no luck.

So why does it work on smaller iphone but not the plus one ?

Can anyone help me:(. Thanks.

Here is the code:

@IBAction func filter(_ sender: Any) {
    let view:FilterViewController = self.storyboard?.instantiateViewController(withIdentifier: "FilterViewController") as! FilterViewController
    view.superVC = self
    view.currentFilter = currentFilter
    self.setLeftCloseNavigation()
    self.navigationController?.pushViewController(view, animated: true)
}

func setLeftCloseNavigation(){
    self.navigationController?.navigationBar.backgroundColor = UIColor.clear
    self.navigationController?.navigationBar.isTranslucent = true
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController?.navigationBar.layer.mask = nil

    self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "icon_close")?.withRenderingMode(.alwaysOriginal)
    self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "icon_close")?.withRenderingMode(.alwaysOriginal)
    navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}

And here is the viewDidLoad in pushed controller:

override func viewDidLoad() {
    super.viewDidLoad()
    statusBar = UIColor.black
    setResetNavigation() }

func setResetNavigation(){
    navigationItem.hidesBackButton = false

    let skipButton = UIButton(frame: CGRect(x: 0, y: 0, width: 70, height: 30))
    skipButton.setTitle("Reset all".localized(), for: .normal)
    skipButton.setTitleColor(UIColor.black, for: .normal)
    skipButton.titleLabel?.font = UIFont(name: "HJGothamMedium", size: 16)
    skipButton.addTarget(self, action: #selector(resetAllClicked), for: .touchUpInside)
    let skip = UIBarButtonItem(customView: skipButton)
    navigationItem.rightBarButtonItem = skip
}

This is the view hierarchy

enter image description here

6 Answers6

2

Add this function :

   override func viewDidAppear(_ animated: Bool) {
          setResetNavigation()
          self.navigationController?.navigationBar.backItem?.title = ""
    }

navigation bar in iPhone 7S

Harshil Kotecha
  • 2,846
  • 4
  • 27
  • 41
0

try this

 self.navigationItem.hidesBackButton = true

Or Check your storyboard it will remain

Lalit kumar
  • 1,797
  • 1
  • 8
  • 14
0

Use the below line to remove the text

navigationController?.navigationBar.topItem?.title = ""
harshal jadhav
  • 5,456
  • 2
  • 18
  • 26
  • Thank you, I tried but it didn't work :(. I placed this in both previous controller (before push) and in presenting controller (viewdidload, viewdidappear) – bui manhcuong Apr 25 '17 at 09:09
  • what is that cross.if its a button see if you mistakenly put the name Back to that button along with a cross image – harshal jadhav Apr 25 '17 at 09:20
0

You can inspect your UI hierarchy and if found related view then remove that view :

You can also invoke the view debugger by choosing View UI Hierarchy from the process view options menu in the debug navigator, or by choosing Debug > View Debugging > Capture View Hierarchy.

KKRocks
  • 8,222
  • 1
  • 18
  • 84
0

From below code you can set backButton text colour to any colour you want.You can simply set backButton to clear textColor. So, It won't be visible when it presents.

 UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.classForCoder() as! UIAppearanceContainer.Type]).setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)

Update: If you want to go for a different approach.Check this post How to customize the navigation back symbol and navigation back text? and accepted answer.

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

To hide the back text you need to set navigation item title to space character on the view controller that pushes the presented view controller:

self.navigationItem.title = " "

Be aware you have to set it on the previous view controller and not on top most one. Also you have to set a space character and not an empty string !!!

Also you can do this directly on storyboard

enter image description here

Zell B.
  • 10,266
  • 3
  • 40
  • 49