yselimguner
yselimguner

Reputation: 21

Hide Navigation Item but show Back Bar Button

Now, I will put an image at the top of the screen in the design I created. However, the Navigation Title area is displaying the image in white color. Since I need the back button, I want to move the white color from the Navigation Title to below it. But I still want to keep the back button. How can I easily do this? Please assist me.enter image description here

self.navigationController?.isNavigationBarHidden = true self.navigationItem.setHidesBackButton(false, animated: false)

I tried this actions but this solutions navigation Item disappear on my screen back button also hidden. I don't want this.

Upvotes: 0

Views: 54

Answers (2)

Geoff Hackworth
Geoff Hackworth

Reputation: 3104

Your question is a little unclear, but since you talk about a back button we can assume that the view controller with the picture has been pushed on a navigation controller. The navigation bar in your image looks very non-standard and doesn’t extend to the top of the screen. But your question has tags that imply you are using the standard navigation controller and bar classes.

You can customise the appearance of the navigation bar when your picture view controller is top-most in the stack:

override func viewDidLoad() {
    super.viewDidLoad()
        
    let appearance = UINavigationBarAppearance()
    appearance.configureWithTransparentBackground()

    navigationItem.standardAppearance = appearance
    navigationItem.compactAppearance = appearance
    navigationItem.scrollEdgeAppearance = appearance
}

Upvotes: 0

Supriyo Dey
Supriyo Dey

Reputation: 256

First make a custom back button in storyboard.

Hide the navigation bar in viewDidLoad()

self.navigationController?.isNavigationBarHidden = true

And use this line of code.

    @IBAction func customBackButton(_ sender: UIButton) {
    self.navigationController?.popViewController(animated: true)
}

Am sure it will help you. Thank you.

Upvotes: 0

Related Questions