Reputation: 2838
I am trying to remove the outer space (marked in red) from ListView.
This issue appeared in iOS 14 and Xcode 12 GM.
Here is the code I am using:
struct ContentView: View {
var menuItems:[String] = ["Item 1", "Item 2", "Item 3"]
var body: some View {
List(self.menuItems, id:\.self) { title in
MenuRow(title: title)
}
}
}
struct MenuRow:View {
var title:String
var body: some View {
HStack(alignment: .center) {
Text(title)
.foregroundColor(Color.black)
.font(Font.system(size: 14,
weight: .regular,
design: .default))
Spacer()
Text(title)
.foregroundColor(Color.black)
.font(Font.system(size: 14,
weight: .regular,
design: .default))
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.listRowInsets(EdgeInsets())
.background(Color.white)
}
}
Upvotes: 1
Views: 1289
Reputation: 246
This worked for me. For the list add:
List {
...
}
.environment(\.defaultMinListRowHeight, 23)
Upvotes: 0
Reputation: 54426
For .listRowInsets
to work you need to use a ForEach
inside a List
:
List {
ForEach(self.menuItems, id:\.self) {
MenuRow(title: $0)
}
}
Upvotes: 1