BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.