Mattia Astorino
Mattia Astorino

Reputation: 1576

SwiftUI MacOS Inset paddings of List

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:

enter image description here

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

enter image description here

Upvotes: 2

Views: 1078

Answers (2)

Mattia Astorino
Mattia Astorino

Reputation: 1576

Just solved by adding Spacer before and after the loop.

Upvotes: 0

Asperi
Asperi

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

Related Questions