I’m working on a SwiftUI application for macOS and am encountering an issue where a .sheet modal that uses .ultraThinMaterial is not blending as expected with the underlying background. I want the modal to have a semi-transparent look that allows the background color to show through, but currently, it appears opaque.
Here’s the relevant part of my code:
import SwiftUI
struct ContentView: View {
@State private var showModal = false
var body: some View {
ZStack {
Color.blue
.edgesIgnoringSafeArea(.all)
Button("Show Modal") {
showModal.toggle()
}
.buttonStyle(.bordered)
.sheet(isPresented: $showModal) {
ModalContentView()
}
}
}
}
struct ModalContentView: View {
var body: some View {
ZStack {
Text("This is a modal view")
.font(.title)
.foregroundColor(.white)
}
.frame(width: 300, height: 200)
.background(.ultraThinMaterial)
.cornerRadius(12)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I expect the modal to show the blue background slightly through its content due to the .ultraThinMaterial, but it does not blend at all. How can I adjust the modal or its background to achieve the desired blending effect with the color set in the ContentView?
Any suggestions or insights would be greatly appreciated. Thank you!