UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: How do I get rid of the white region on top of a NavigationView

Forums > SwiftUI

@Apps  

I need to use a NavigationView because I need a search box there.

This is a sample code, very basic.

@State var searchText = ""

var body: some View {
    NavigationView {
      List {
        NavigationLink(destination: Color(.red) ) {
          Text("aaa")
        }
        NavigationLink(destination: Color(.red) ) {
          Text("bbb")
        }
        NavigationLink(destination: Color(.red) ) {
          Text("ccc")
        }
      }

    }
    .searchable(text: $searchText, prompt: "search...")
    .navigationBarTitle("", displayMode: .inline)
    .edgesIgnoringSafeArea(.top)

    .navigationBarHidden(true)
}

This is the result

Look at the annoying area at the top (I have colored it yellow on Photoshop for reference).

How do I get rid of this area and move the search box up?

2      

I'm not sure but I think it has to do with

    .navigationBarTitle("", displayMode: .inline)

does it help to remove that line?

2      

@Apps  

Nope, no difference at all.

2      

@Apps  

I have discovered the problem. Just change the commands to the list...


@State var searchText = ""

var body: some View {
NavigationView {
List {
NavigationLink(destination: Color(.red) ) {
Text("aaa")
}
NavigationLink(destination: Color(.red) ) {
Text("bbb")
}
NavigationLink(destination: Color(.red) ) {
Text("ccc")
}
}
.searchable(text: $searchText, prompt: "search...")
.navigationBarTitle("", displayMode: .inline)
.navigationBarHidden(true)
}

}
.edgesIgnoringSafeArea(.top)
}

Thanks Apple.

2      

@Bnerd  

if you enable .navigationBarHidden , there is no more search, so how this solved your problem?

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.