I have a navigation view housing some elements (example shown below, take note of the space above), and for some reason, there is excess space on the top. More specifically, I am working on an app for iPad, and the excess space on top is bugging me. An excerpt of my code is shown below.
var body: some View {
NavigationView {
Text("There is an excess space above")
}.navigationViewStyle(StackNavigationViewStyle())
.navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarHidden(true)
.edgesIgnoringSafeArea(.top)
}
I've used .navigationViewStyle(StackNavigationViewStyle())
because of the problem solved here, and the other methods were called just in an attempt to remove this space (from other similar questions here), but didn't work in the end. This happens to both iPhone and iPad simulations. Thanks
After a few trials and errors, I managed to get the blue border to cover the entire screen (Note the blue borders in the following screenshot). Not entirely sure why yet, but all of the following lines have to be present for the solution to work. @Asperi mentioned that we have to add the modifiers to inside the navigation view, but for some reason we have to add to both the NavigationView itself, and inside it as well.
var body: some View {
NavigationView {
Text("There is no more excess space, the blue outline covers the entire screen")
.frame(maxWidth: .infinity, maxHeight: .infinity) // Fill screen
.navigationBarTitle("")
.navigationBarHidden(true)
}
.navigationViewStyle(StackNavigationViewStyle())
.navigationBarTitle("")
.edgesIgnoringSafeArea(.all)
}