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
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)
Just solved by adding Spacer
before and after the loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.