SwiftUI macos 磨砂窗口 毛玻璃 背景高斯模糊

struct BlurView: NSViewRepresentable {
    
    func makeNSView(context: Context) -> NSVisualEffectView {
        
        let blurView = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
        blurView.blendingMode = NSVisualEffectView.BlendingMode.behindWindow
        blurView.material = NSVisualEffectView.Material.hudWindow
        blurView.isEmphasized = true
        blurView.state = NSVisualEffectView.State.active
        
        return blurView;
    }
    
    func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
        NSLog("updateNSView")
    }
    
    func test() -> some View {
        NSLog("Test")
        return self
    }
};

struct ContentView: View { 
    var body: some View {
        Button(action: {}, label: {
            Image(systemName: "sidebar.leading")
            Text("更改")
        })//.frame(width: 300, height: 300, alignment: .topLeading)
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .frame(minWidth: 300, minHeight: 300)
        .background(BlurView().test())
        .ignoresSafeArea()
    }
}
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容