Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the left and right Padding of a List in SwiftUI?

Tags:

swift

swiftui

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?

like image 394
Just a coder Avatar asked Jun 15 '19 20:06

Just a coder


People also ask

What is padding () in Swift?

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") .

What is the default padding in SwiftUI?

If you set the value to nil , SwiftUI uses a platform-specific default amount. The default value of this parameter is nil .

How do I add padding to SwiftUI?

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(_:) .


1 Answers

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())     } } 
like image 134
Avario Avatar answered Sep 22 '22 17:09

Avario