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.)
}
}
You'll also have to define the following Struct.
Result: