Reputation: 2545
How would I set the gray background of the List
to be fully transparent to let the red come through?
struct ContentView: View {
var body: some View {
NavigationView {
ZStack {
Color.red
.ignoresSafeArea()
VStack {
HStack {
Text("Faux Title")
.font(.system(.largeTitle, design: .rounded))
.fontWeight(.heavy)
Spacer()
Button(action: {
// settings
}, label: {
Image(systemName: "gearshape.fill")
.font(.system(.title2))
})
}
.padding()
.navigationBarHidden(true)
List {
Text("One")
Text("Two")
Text("Three")
}
.listStyle(InsetGroupedListStyle())
}
}
}
}
}
Upvotes: 1
Views: 1226
Reputation: 21
In IOS 16 you can use:
List {
Text("test-item")
}.scrollContentBackground(.hidden)
Upvotes: 2
Reputation: 1
In init() of View changing UITableView.appearance
:
The most things that we are using in SwiftUI such as List or NavigationView, . . they are not pure SwiftUI and they are coming from UIKit, therefore we use UIKit code type for changing appearance. if you remember we should use such codes in UIKit. And when we use UITableView
in init we are accessing to the class of UITableView UIKit, it means this change would apply to any View in our project which they are using List.
The best way is the way you are doing, setting transparent Color, then changing Color from SwiftUI in body! that is the most convenient way.
struct ContentView: View {
init() { UITableView.appearance().backgroundColor = UIColor.clear } // <<: here!
var body: some View {
NavigationView {
ZStack {
Color.red
.ignoresSafeArea()
VStack {
HStack {
Text("Faux Title")
.font(.system(.largeTitle, design: .rounded))
.fontWeight(.heavy)
Spacer()
Button(action: {
// settings
}, label: {
Image(systemName: "gearshape.fill")
.font(.system(.title2))
})
}
.padding()
.navigationBarHidden(true)
List {
Text("One")
Text("Two")
Text("Three")
}
.listStyle(InsetGroupedListStyle())
}
}
}
}
}
Upvotes: 2