I'm looking for a way to display a SwiftUI Table or List at its "intrinsic size" without including empty rows or empty space below the rows, as it does in the following example, in which the table is given a blue border for clarity:
It is generated by the following code:
struct ContentView: View {
let names = ["Achmed", "Balthus", "Chaim"]
var body: some View {
VStack {
Text("List of Names")
.font(.largeTitle)
.padding()
List(names, id: \.self) { Text($0) }
.border(.blue)
.padding()
Spacer()
}
}
}
I would like the Spacer() to reduce the height of the List, removing the extra space inside the List View below its last row - but it does not.
Nor does adding .fixedSize() modifier. (I wonder why the list doesn't have an idealHeight that does not include empty rows, such that adding .fixedSize() would cause it to be displayed that way.)


This works for iOS, I changed the listStyle to
insetGroupedand commented outpadding(). Also,alternatingRowBackgroundsgave a compiler error, so I commented that one out as well.Result:
For macOS, you could try
.listStyle(.automatic).EDIT: try using a
GeometryReader:Result:
You will have to tweak the
.frame(height: g.size.height / 3)part for your specific case.