Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide NavigationView Bar in SwiftUI

I cannot hide NavigationView bar. I tried both variants:

Code 1:

  public var body: some View {
    NavigationView {
      MasterView()
        .navigationBarHidden(true)
    }
  }

Code 2:

  public var body: some View {
    NavigationView {
      MasterView()
    }
      .navigationBarHidden(true)
  }

Does anyone have an idea how to fix it?

like image 497
Bohdan Savych Avatar asked Aug 01 '19 13:08

Bohdan Savych


People also ask

How do I hide navigation bar in SwiftUI?

Use navigationBarHidden(_:) to hide the navigation bar. This modifier only takes effect when this view is inside of and visible within a NavigationView .

How do I hide the navigation bar back button in SwiftUI?

The . navigationBarBackButtonHidden(true) will hide the back button.

What is NavigationView SwiftUI?

NavigationView is one of the most important components of a SwiftUI app, allowing us to push and pop screens with ease, presenting information in a clear, hierarchical way for users.


1 Answers

Seems that the solution could be adding a title or removing the space from safe area.

The problem:

enter image description here

Solution 1:

.navigationBarHidden(true)
.navigationBarTitle(Text("Home"))

Solution 2 (this seems be the best):

.navigationBarHidden(true)
.navigationBarTitle(Text("Home"))
.edgesIgnoringSafeArea([.top, .bottom])

enter image description here

like image 196
Giuseppe Sapienza Avatar answered Oct 17 '22 04:10

Giuseppe Sapienza