Updated for Xcode 12.5
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)
You can blur anything you want, including text views:
Text("Welcome to my SwiftUI app")
.blur(radius: 2)
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: CGFloat = 0
var body: some View {
VStack {
Text("Drag the slider to blur me")
.blur(radius: blurAmount)
Slider(value: $blurAmount, in: 0...20)
}
}
}
SPONSORED ViRE offers discoverable way of working with regex. It provides really readable regex experience, code complete & cheat sheet, unit tests, powerful replace system, step-by-step search & replace, regex visual scheme, regex history & playground. ViRE is available on Mac & iPad.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.