How to remove the left and right Padding of a List in SwiftUI? Every List i create has borders to the leading and trailing of a cell.
What modifier should I add to r
Seem we can use PlainListStyle for List for iOS 14
List {
Text("Row")
}
.listStyle(PlainListStyle())
You should call
.listRowInsets()
for row, like this:
List(items) {
YoursRowView()
.listRowInsets(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
}
It looks like .listRowInsets doesn't work for rows in a List that is initialised with content.
So this doesn't work:
List(items) { item in
ItemRow(item: item)
.listRowInsets(EdgeInsets())
}
But this does:
List {
ForEach(items) { item in
ItemRow(item: item)
.listRowInsets(EdgeInsets())
}
}
The modifier was
.listRowInsets(EdgeInsets(......))
Use this modifier:
.listRowInsets(EdgeInsets(....))
However, as stated in the documentation, the insets will be applied to the view when inside a list.
Sets the inset to be applied to the view when placed in a list. (emphasis mine)
Using this modifier on the List itself will have no effect on the views inside it. You must use the modifier on the view inside the List for the modifier to have an effect.
Example usage:
List {
Text("test")
.listRowInsets(EdgeInsets(top: -20, leading: -20, bottom: -20, trailing: -20))
}
.listStyle(GroupedListStyle())