SwiftUI-如何模糊视图的默认背景色? [英] SwiftUI - How can I blur the default background color of a view?

查看:170
本文介绍了SwiftUI-如何模糊视图的默认背景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里没有代码显示,但是我想知道这样做的可能性.我尝试使用

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))

这篇关于SwiftUI-如何模糊视图的默认背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆