I have some troubles with dynamically changing List height that dependent on elements count.
I tried this solution but it didn\'t work.
List {
Fo
List
:If you want a List
to show it's content all at once, It means you don't need the recycling feature (the key feature of the list), So all you need is to not using a List
! Instead, you can use ForEach
directly, then it will size itself based on it's content:
ForEach(searchService.searchResult, id: \.self) { item in
VStack(alignment: .leading) {
Text(item).font(.custom("Avenir Next Regular", size: 12))
Divider()
}.padding(.horizontal, 8)
}
You can change all sizes and spacings according to your needs
Note that You can use LazyVStack
from iOS 14 to make it lazy-load and boost its performance.