Can someone tell me how to add a gradient background on SwiftUI List?
Current code:
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)
)
}
}
Current layout, where the gradient is visible behind the cells. I want to make the cells transparent to see the gradient underneath.
Thanks!
You have already added the gradient. Just make background colors clear and get rid of those test codes ;)
You can hide the background of any scrollable content using scrollContentBackground(.hidden)
modifier
You should hide the default list background and all cell's using the appearance
property of the UITableView
and UITableViewCell
Also you can hide the cell background using .listRowBackground(.clear)
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)
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With