Simple list embedded in navigation view renders as expected:
NavigationView {
List {
HStack {
Text("Row 1")
}
HStack {
Text("Row 2")
}
HStack {
Text("Row 3")
}
}
}
But as soon as I add navigation bar button, I get unexpected paddings around the List.
NavigationView {
List {
HStack {
Text("Row 1")
}
HStack {
Text("Row 2")
}
HStack {
Text("Row 3")
}
}
.navigationBarItems(leading: Button("Add") {})
}
Where are those paddings are coming from and how to get rid of them?
That is the default listStyle
for that combination. You should explicitly set that to plain
:
.listStyle(PlainListStyle())