Reputation: 1576
i have a scrollale list view using SwiftUI on a macOS app and i'm trying to add paddings inside the scrollable area, without success. Here my code:
List(appListItems, id: \.self, selection: $selectedItem) { app in
ApplistItem(item: app, selected: selectedItem?.hashValue == app.hashValue)
}
.background(Color.red)
.padding(24)
but what i get is this:
What the design requires is this, as you can see i want the scrollbar to stay on the right edge and the top/bottom distance should be included in the scroll area, and not put outside it. The horizontal paddings are not required, but i can't figure out how to handle top and bottom paddings and keep them inside the scroll area
Upvotes: 2
Views: 1078
Reputation: 257523
You need list row insets, but it is applied to dynamic content, so you need to use ForEach
, like
List {
ForEach(appListItems, id: \.self, selection: $selectedItem) { app in
ApplistItem(item: app, selected: selectedItem?.hashValue == app.hashValue)
}
.listRowInsets(EdgeInsets(top: 0, leading: 24, bottom: 0, trailing: 24))
}
.background(Color.red)
Upvotes: 2