Reputation: 15
I want to reduce the size of the items in a List
view, more precisely the height, the list being styled like a sidebar (.listStyle(.sidebar)
). I tried changing the size with .controlSize(.mini)
but it didn't work. It worked for other list styles (plain, bordered, etc.).
What strikes me is that Xcode sidebar does have list items that are smaller than the regular size, so it should be possible !
Side by side comparison between Xcode sidebar and my app sidebar
Is there a simple and idiomatic way to do this ?
Upvotes: 0
Views: 197
Reputation: 1
I'm in this same situation as well. The .frame(.height: solution does not change the spacing. I've had success in changing the spacing in the preview, but the sidebar style seems to space it out no matter what.
Upvotes: 0
Reputation: 2319
Apologies if I am not correctly understanding the question but can't you just set the frame
of the items? For example:
struct SwiftUIView: View {
var body: some View {
List {
ForEach((1...10), id: \.self) {_ in
Text("hello")
.frame(height: 50) // <- Right here!
}
}
.listStyle(.sidebar)
}
}
Where 50 would be the height you want.
Upvotes: 1