[英]SwiftUI MacOS Inset paddings of List
我在 macOS 應用程序上有一個使用 SwiftUI 的滾動列表視圖,我試圖在可滾動區域內添加填充,但沒有成功。 這是我的代碼:
List(appListItems, id: \.self, selection: $selectedItem) { app in
ApplistItem(item: app, selected: selectedItem?.hashValue == app.hashValue)
}
.background(Color.red)
.padding(24)
但我得到的是:
設計要求是這樣的,如您所見,我希望滾動條保持在右邊緣,並且頂部/底部距離應包含在滾動區域中,而不是放在滾動區域之外。 不需要水平填充,但我不知道如何處理頂部和底部填充並將它們保持在滾動區域內
您需要列表行插圖,但它適用於動態內容,因此您需要使用ForEach
,例如
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)
只需在循環前后添加Spacer
解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.