xcode - SwiftUI:listRowInsets 未按预期工作
问题描述
listRowInsets(_:)
使用List()
and时没有按预期工作List(Data,id)
。在下面的示例 1中,零插入完美地工作,而在示例 2中它什么也不做。
示例 1:
struct ContentView: View {
var body: some View {
List {
Color.red
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.blue
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.yellow
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
结果:
示例 2
struct ContentView: View {
var colors: [Color] = [.red, .blue, .yellow]
var body: some View {
List(colors, id: \.self) { color in
color.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
结果:
解决方案
我认为原因在于使用过的构造函数。.listRowInsets
按文档效果视图被放置在列表中(直接)。
以下作品
var colors: [Color] = [.red, .blue, .yellow]
var body: some View {
List {
ForEach(colors, id: \.self) { color in
color.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
推荐阅读
- r - R,删除未指定的因子水平
- opencv - Open CV 上的 CLAHE 是否适用于浮点像素?
- google-chrome-extension - 在 Chrome 扩展程序中以开发人员模式在本地使用 web_accessible_resources 是否有限制?
- ios - Xcode中firebase的登录身份验证问题
- ios - iOS SwiftUI 小部件问题,小部件在物理设备上添加到锁屏/主页时会加载旧/默认数据
- javascript - TypeError:无法使用反应图像读取未定义的属性“活动”
- scoping - 如果 JavaScript 是动态作用域,那么最后一个 console.log() 会在以下代码中产生什么结果?
- python - 有 if 或 in 列表理解
- typescript - 如何检查某些东西是否可以是 TypeScript 中的字符串?
- docker - 是否可以分别推送不同架构的 docker 镜像?