bui manhcuong
bui manhcuong

Reputation: 51

Swift strange back button text in iphone plus

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

Upvotes: 1

Views: 584

Answers (6)

Joe
Joe

Reputation: 8986

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.

Upvotes: 0

Harshil Kotecha
Harshil Kotecha

Reputation: 2896

Add this function :

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

navigation bar in iPhone 7S

Upvotes: 2

Zell B.
Zell B.

Reputation: 10286

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

Upvotes: 0

KKRocks
KKRocks

Reputation: 8322

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.

Upvotes: 0

harshal jadhav
harshal jadhav

Reputation: 5684

Use the below line to remove the text

navigationController?.navigationBar.topItem?.title = ""

Upvotes: 0

Lalit kumar
Lalit kumar

Reputation: 2207

try this

 self.navigationItem.hidesBackButton = true

Or Check your storyboard it will remain

Upvotes: 0

Related Questions