4

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?

Isaiah Thomas
  • 53
  • 1
  • 4

1 Answers1

11

It is possible to apply blur directly to background only, like in the example below

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

blur button

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690
  • Nice! Thank you. Is it possible to do it without specifying the color of the rectangle? I noticed yours was red. If not I will most likely just blur grey. – Isaiah Thomas Dec 30 '19 at 07:49