I might be missing something obvious here, but I can't find how to get around it. I want to have List() with limited height, that allows me to scroll inside it. This is an example code:
struct TestView: View {
var items: [String] = [
"Item 1", "Item 2", "Item 3",
"Item 4", "Item 5", "Item 6",
"Item 7", "Item 8", "Item 9",
"Item 10"
]
@State var selected: String = "one"
var body: some View {
Form {
Section(header: Text("A section")) {
List(selection: $selected) {
ForEach(items, id: \.self) { item in
Text(item)
}
}
.frame(height: 100)
}
}
.formStyle(.grouped)
}
}
I was expecting the List to allow me to scroll inside the 100pt height, but instead the list is just cut off, without any possibility of scrolling. If I wrap the whole List in a ScrollView, everything disappears.
How to enable scrolling of a List inside explicitly limited space?
Listin aFormcan be tricky. Move theListoutside theForm. You could also try usingScrollViewinstead of aList.