我正在尝试删除一些部分的白色背景,以便元素正好位于灰色背景上,但我无法删除或透明部分的背景。
这就是我正在尝试的:
struct ContentView: View {
var body: some View {
Form {
Section {
Text("Hello!")
Button {
print("Clicked")
} label: {
Text("Click Me!!")
}
}
Section {
VStack {
Button("Button 1") {}
Spacer()
Button("Button 2") {}
}
}
.background(Color.clear) // Not doing anything
Section {
VStack(alignment: .leading) {
Text("Location")
.font(.headline)
Group {
Text("Abc")
Text("Abc")
Text("Abc")
}
.font(.caption)
}
}
}
}
}
它看起来是这样的:
我尝试将.background(Color.clear)
添加到Section
和VStack
中,但没有任何效果。如何在SwiftUI中实现这一点?
发布于 2020-09-17 21:08:46
即使在SwiftUI 2中,Form
也是建立在UIKit之上的,特别是UITableView
。
您需要移除默认 UITableViewCell
的背景(仅一次,init
App init 中):
UITableViewCell.appearance().backgroundColor = UIColor.clear
并使用以下命令更改背景:
Section {
VStack {
Button("Button 1") {}
Spacer()
Button("Button 2") {}
}
}
.listRowBackground(Color.clear)
https://stackoverflow.com/questions/63945992
复制