Skip to main content

How to blur a view

About 2 minSwiftSwiftUIArticle(s)bloghackingwithswift.comcrashcourseswiftswiftuixcodeappstore

How to blur a view 관련

SwiftUI by Example

Back to Home

How to blur a view | SwiftUI by Example

How to blur a view

Updated for Xcode 15

The blur() modifier lets us apply a real-time Gaussian blur to our views, at a strength of our choosing.

For example, this creates a 300x300 profile picture, then adds a 20-point Gaussian blur:

Image("dog")
    .resizable()
    .frame(width: 300, height: 300)
    .blur(radius: 20)

Download this as an Xcode projectopen in new window

A very blurry image of a vague dog head shape.
A very blurry image of a vague dog head shape.

You can blur anything you want, including text views:

Text("Welcome to my SwiftUI app")
    .blur(radius: 2)

Download this as an Xcode projectopen in new window

The text “Welcome to my SwiftUI app” in blurry print.
The text “Welcome to my SwiftUI app” in blurry print.

Blurring is extremely efficient, and you can adjust it dynamically just like any other kind of state. For example, this lets you try adjusting the blur of our text dynamically by dragging around a slider:

struct ContentView: View {
    @State private var blurAmount = 0.0

    var body: some View {
        VStack {
            Text("Drag the slider to blur me")
                .blur(radius: blurAmount)

            Slider(value: $blurAmount, in: 0...20)
        }
    }
}

Download this as an Xcode projectopen in new window

Similar solutions…
SwiftUI tips and tricks | SwiftUI by Example

SwiftUI tips and tricks
How to convert a SwiftUI view to an image | SwiftUI by Example

How to convert a SwiftUI view to an image
How to make a view dismiss itself | SwiftUI by Example

How to make a view dismiss itself
How to dynamically adjust the appearance of a view based on its size and location | SwiftUI by Example

How to dynamically adjust the appearance of a view based on its size and location
How to create and compose custom views | SwiftUI by Example

How to create and compose custom views

이찬희 (MarkiiimarK)
Never Stop Learning.