[英]SwiftUI macOS List Row removing padding
现在我只找到了解决方法( .listRowInsets
应该真正完成这项工作,因此值得向 Apple 提交反馈):
struct TestListRow: View {
var body: some View {
List {
ForEach (0..<3) { i in
HStack {
Text("Test row \(i)").font(.largeTitle)
Spacer()
}
}
.listRowBackground(Color.green)
.border(Color.red)
.padding(.horizontal, -8) // << workaround !!
}.environment(\.defaultMinListRowHeight, 40)
.border(Color.yellow)
}
}
我在行尾添加了这段代码,填充缩小了!!!
Spacer()
Text(" ")
.padding()
示例代码
import SwiftUI
struct testViews1: View {
var body: some View {
List {
ForEach (0..<3) { i in
HStack {
Text("row \(i)")
Spacer()
}
.background(Color.red)
.frame(height: 30)
}
}
}
}
struct testViews2: View {
var body: some View {
List {
ForEach (0..<3) { i in
HStack {
Text("row \(i)")
Spacer()
Text(" ")
.padding()
}
.background(Color.red)
.frame(height: 30)
}
}
}
}
struct testViews_Previews: PreviewProvider {
static var previews: some View {
testViews1()
.frame(height: 150)
testViews2()
.frame(height: 150)
}
}
它适用于 SwiftUI 1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.