在 SwiftUI Form 中填充 Section 背景
Fill the Section background in SwiftUI Form
我必须像这样用某种颜色填充一个部分的背景
现在我试过了
NavigationView {
Form {
Section {
Text("Error message!")
}.background(Color.red.opacity(0.2))
Section {
Text("Label 1")
}
Section {
Text("Label 2")
}
}.navigationBarTitle("title", displayMode: NavigationBarItem.TitleDisplayMode.inline)
}
但是,似乎有一个预定义的填充,所以我无法填充边距
也许这会有所帮助,至少在 Simulator 中这似乎是对您的请求的解决方案:
NavigationView {
Form {
Section {
HStack {
Text("Error message!")
Spacer()
}
.padding(.vertical)
.listRowInsets(EdgeInsets())
}
.padding(.horizontal)
.background(Color.red.opacity(0.2))
Section {
Text("Label 1")
}
Section {
Text("Label 2")
}
}
.navigationBarTitle("title", displayMode: .inline)
}
我必须像这样用某种颜色填充一个部分的背景
现在我试过了
NavigationView {
Form {
Section {
Text("Error message!")
}.background(Color.red.opacity(0.2))
Section {
Text("Label 1")
}
Section {
Text("Label 2")
}
}.navigationBarTitle("title", displayMode: NavigationBarItem.TitleDisplayMode.inline)
}
但是,似乎有一个预定义的填充,所以我无法填充边距
也许这会有所帮助,至少在 Simulator 中这似乎是对您的请求的解决方案:
NavigationView {
Form {
Section {
HStack {
Text("Error message!")
Spacer()
}
.padding(.vertical)
.listRowInsets(EdgeInsets())
}
.padding(.horizontal)
.background(Color.red.opacity(0.2))
Section {
Text("Label 1")
}
Section {
Text("Label 2")
}
}
.navigationBarTitle("title", displayMode: .inline)
}