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      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.