有人可以告诉我如何在SwiftUI列表上添加渐变背景吗?
当前代码:
struct TestView: View {
var body: some View {
LinearGradient(gradient: Gradient(colors: [Color.red, Color.purple]), startPoint: .top, endPoint: .bottom)
.edgesIgnoringSafeArea(.vertical)
.overlay(
List {
Group {
Text("Hallo")
Text("World")
}
.background(Color.blue)
}
.background(Color.green)
.padding(50)
)
}
}
当前布局,其中在单元格后面可见渐变。我想使单元透明,以查看下面的渐变。
谢谢!
答案 0 :(得分:3)
您已经添加了渐变。只需弄清楚背景颜色并清除那些测试代码即可;)
struct TestView: View {
init() {
UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().backgroundColor = .clear
}
var body: some View {
LinearGradient(gradient: Gradient(colors: [Color.red, Color.purple]), startPoint: .top, endPoint: .bottom)
.edgesIgnoringSafeArea(.vertical)
.overlay(
List {
Group {
Text("Hallo")
Text("World")
}
}
.padding(50)
)
}