GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.

Click to save your free spot now

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.