How to add visual effect blurs
About 2 min
How to add visual effect blurs êŽë š
SwiftUI by Example
Back to Home
How to add visual effect blurs | SwiftUI by Example
How to add visual effect blurs
Updated for Xcode 15
New in iOS 15
SwiftUI has a brilliantly simple equivalent to UIVisualEffectView
, that combines ZStack
, the background()
modifier, and a range of built-in materials.
For example, this places some text over an image, applying a standard blur effect to the text:
ZStack {
Image("singapore")
Text("Visit Singapore")
.padding()
.background(.thinMaterial)
}
You can adjust the âthicknessâ of your material â how much of the background content shines through â by using one of several material types. From thinnest to thickest, they are:
.ultraThinMaterial
.thinMaterial
.regularMaterial
.thickMaterial
.ultraThickMaterial
If youâre using the secondary
foreground style, SwiftUI automatically adjusts the text color so that it has a vibrant effect and can stand out from the background:
ZStack {
Image("singapore")
Text("Visit Singapore")
.foregroundStyle(.secondary)
.padding()
.background(.ultraThinMaterial)
}
Similar solutionsâŠ
How to provide visual structure using foreground styles | SwiftUI by Example
How to provide visual structure using foreground styles
How to create a marching ants border effect | SwiftUI by Example
How to create a marching ants border effect
How to add in-app purchases in SwiftUI | SwiftUI by Example
How to add in-app purchases in SwiftUI
How to add Metal shaders to SwiftUI views using layer effects | SwiftUI by Example
How to add Metal shaders to SwiftUI views using layer effects
Two-way bindings in SwiftUI | SwiftUI by Example
Two-way bindings in SwiftUI