Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController without navigation bar?

People also ask

How do I push a controller without navigation controller?

You can't push a view controller onto a navigation controller if there is no navigation controller. If you are wanting to be pushing controllers and have it display the topmost controller and everything, just use a UINavigationController and be done with it.

How do I hide navigation bar in storyboard?

Click on the controller that has the top bar navigate to the properties bar on the right hand side of Xcode. There is a drop down labeled Top Bar (as shown above) change this drop down to none.

How do I hide the top navigation bar in Swift?

How To Hide Navigation Bar In Swift. To hide the navigation bar in Swift, you'll need to add code to two methods: viewWillAppear and viewWillDisappear . That's it to hide the navigation bar in your view controller.


You should be able to do the following:

self.navigationController.navigationBar.isHidden = true //Swift 5

where self.navigationController is (obviously) an instance of UINavigationController. Seems to work for me, but I only briefly tested it before posting this.


If you want no navigation bar, and you want the content to be adjusted up to where the navigation bar normally would be, you should use

self.navigationController.navigationBarHidden = YES;

This gives you a result like this:

enter image description here

Whereas self.navigationController.navigationBar.hidden = YES; gives you a space where the navigationBar should be. Like this:

enter image description here


In Xcode 4.3.2:

  1. Select the navigation controller in the storyboard
  2. Select the Attributes Inspector in the (right) Utilities panel
  3. Under the Navigation Controller category you have two check boxes:

    [] Shows Navigation Bar

    [] Shows Toolbar

Worked for me...


Swift 4

I hide it in viewWillAppear

     override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.navigationController?.isNavigationBarHidden = true;
    }

Then you can put it back when you push a segue (if you want to have the back button on the next view)

     override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
     {
        self.navigationController?.isNavigationBarHidden = false;
     }

Swift 3 Programmatically

self.navigationController.isNavigationBarHidden = true

or

self.navigationController.navigationBar.isHidden = true

Note: I didn't see a difference between these two approaches testing on iOS 10.


All these answers still leave a space at the top for the status bar - add this line to remove that as well:

navController.navigationBar.isHidden = true
navController.accessibilityFrame = CGRect.zero