Reputation: 904
I'm wondering how to remove the top padding just above the NavigationView in SwiftUI.
Code:
import SwiftUI
struct HomeView: View {
var deeds: [Deed] = deedsData
var body: some View {
NavigationView {
List(deeds) { item in
Image(systemName: "doc.fill")
}
.navigationTitle(Text("title"))
}
}
}
struct HomeView_Previews: PreviewProvider {
static var previews: some View {
HomeView(deeds: deedsData)
}
}
Upvotes: 5
Views: 5327
Reputation: 1503
The space is intended. it makes room for the toolbar items.
however, you could go for negative padding like so:
struct ContentView: View {
var body: some View {
NavigationView{
YourListView()
.navigationTitle("Title")
}.padding(.top, -50)
}
}
Upvotes: 1
Reputation: 257711
Remove NavigationView
from HomeView
, there seems one already present in parent view (and it is enough to construct navigation stack)
struct HomeView: View {
var deeds: [Deed] = deedsData
var body: some View {
List(deeds) { item in
Image(systemName: "doc.fill")
}
.navigationTitle(Text("title"))
}
}
Upvotes: 1
Reputation: 54486
This is the appearance of the large
navigation bar.
You can use the inline
style instead:
List(deeds) { item in
Image(systemName: "doc.fill")
}
.navigationTitle(Text("title"))
.navigationBarTitleDisplayMode(.inline) // change style
Upvotes: 5