I am trying to make the SwiftUI Form translucent. I’ve tried applying .background(.thinMaterial)
modifier to the Form. However, this changes the look of the scroll view background. I’d like to apply translucency to the area that is white in the picture I attached.
Is there a way to do it? I am developing for iOS 16.
var body: some View {
NavigationStack(path: $path) {
ZStack {
LinearGradient(gradient: Gradient(colors: [.pink, .yellow]),
startPoint: .topTrailing,
endPoint: .bottomLeading)
.edgesIgnoringSafeArea(.all)
Form {
VStack {
...
}
}.scrollContentBackground(.hidden)
}
}
2
Answers
Change the form’s opacity to bleed through the background colour/image:
It seems
Form
is just aList
under the hood. So by applying.scrollContentBackground(.hidden)
you are clearing theList
background.By using
.background
onForm
you are setting the background for the entireList
again. To set the background only on the implicitSection
you need another modifier..listRowBackground
.But
listRowBackground
has this signature:So you can´t use
.thinMaterial
. But you can add a new background to theVStack
.A possible solution would be:
Result: