swift - SwiftUI MacOS 列表的 Inset 填充
问题描述
我在 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)
推荐阅读
- c# - 在 ASP.NET MVC5 中将数据传递给 Razor 视图
- css - Bootstrap 4 表,其中一列比其他表大
- php - 一个在php中抓取的工具提示
- php - file_put_contents 导致页面刷新
- ios - 使用 Swift Keychain Wrapper 时意外崩溃
- java - 领域 Java 迁移:已将属性设为必需
- html - iOS 上的 iframe 调整大小问题(不是标准的响应式 iframe)
- python - 使用 Python 和计算机视觉 API 分析基于 Web 的图像时出现 404 错误
- python - 如何在 Python PLY 中列出所有表达式
- python - Python。填充DataFrame:代码优化