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

妖精的绣舞 提交于 2020-12-31 05:43:54

问题


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?


回答1:


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

blur button



来源:https://stackoverflow.com/questions/59527149/swiftui-how-can-i-blur-the-default-background-color-of-a-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!