简体   繁体   English

SwiftUI - 如何模糊视图的默认背景颜色?

[英]SwiftUI - How can I blur the default background color of a view?

no code to show here, but I would like to know how it may be possible to do this.这里没有显示代码,但我想知道如何做到这一点。 I have tried to use我试过用

.blur(radius: (20)

on a view, but it tends to blur the entire view.在一个视图上,但它往往会模糊整个视图。 Including the text, and anything else in the view.包括文本和视图中的任何其他内容。 The default background color is fine and I don't want/need to change it (in order to keep the app compatible with light/dark mode).默认背景颜色很好,我不想/不需要更改它(为了使应用程序与明/暗模式兼容)。 I want to make the view's background slightly blurred/opaque, but I want the text and buttons in the view to still remain full and normal.我想让视图的背景稍微模糊/不透明,但我希望视图中的文本和按钮仍然保持完整和正常。 Is there any way possible to just blur the background color of the view itself?有什么办法可以只模糊视图本身的背景颜色吗?

It is possible to apply blur directly to background only, like in the example below可以仅将模糊直接应用于背景,如下例所示

Button("Test") {}
        .background(Rectangle().fill(Color.red).blur(radius: 20))

模糊按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM