Bellows are the codes in Swift Playground
.
import PlaygroundSupport
import SwiftUI
struct VisualEffectView: NSViewRepresentable
{
let material: NSVisualEffectView.Material = .contentBackground
let blendingMode: NSVisualEffectView.BlendingMode = .withinWindow
func makeNSView(context: Context) -> NSVisualEffectView
{
let visualEffectView = NSVisualEffectView()
visualEffectView.material = material
visualEffectView.blendingMode = blendingMode
visualEffectView.state = NSVisualEffectView.State.active
return visualEffectView
}
func updateNSView(_ visualEffectView: NSVisualEffectView, context: Context)
{
visualEffectView.material = material
visualEffectView.blendingMode = blendingMode
}
}
struct ContentView: View {
var body: some View {
ZStack {
Image(nsImage: #imageLiteral(resourceName: "background.jpg"))
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 400, height: nil, alignment: .center)
VisualEffectView()
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
The codes result in white area with the Image
invisible.