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 remove this?
SwiftUI lets us set individual padding around views using the padding() modifier, causing views to be placed further away from their neighbors. If you use this with no parameters you'll get system-default padding on all sides, like this: VStack { Text("Using") Text("SwiftUI") .
If you set the value to nil , SwiftUI uses a platform-specific default amount. The default value of this parameter is nil .
SwiftUI chooses a default amount of padding that's appropriate for the platform and the presentation context. To control the amount of padding independently for each edge, use padding(_:) . To pad all outside edges of a view by a specified amount, use padding(_:) .
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()) } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With