WWDC21 SALE: Save 50% on all my Swift books and bundles! >>

How to add visual effect blurs

Paul Hudson    @twostraws   

In the process of being updated for Xcode 13.0

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 {

    Text("Visit Singapore")

Download this as an Xcode project

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 color, SwiftUI automatically adjusts the text color so that it has a vibrant effect and can stand out from the background:

ZStack {

    Text("Visit Singapore")

Download this as an Xcode project

Save money with our WWDC sale!

SAVE 50% To celebrate WWDC21, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Similar solutions…

Buy Pro Swift Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift (Vapor Edition) Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Server-Side Swift (Kitura Edition) Buy Beyond Code

Was this page useful? Let us know!

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.