1
votes

SwiftUI 3 introduced the concept of system materials – akin to a UIVisualEffectView with a UIBlurEffect.

    Text("Hello world!")
        .padding()
        .background(.thinMaterial)

How do I change the intensity of blur applied by a system material?

1

1 Answers

1
votes

SwiftUI currently does not offer a way to achieve this. It is, however, possible to achieve using SwiftUIX.

  1. Install SwiftUIX via the Swift Package Manager.
  2. In your code, import SwiftUIX.
  3. Use VisualBlurEffectView with the .intensity(_:) modifier.
Text("Hello world!")
    .background {
        VisualEffectBlurView(blurStyle: .systemThinMaterial)
            .intensity(0.5)
    }

Disclaimer: Both this answer and the question were written to document SwiftUIX (an MIT-licensed open-source package) in a Q/A style format. As of writing this question I am currently not aware of any simple way to achieve this via UIKIt, and will gladly amend the answer to prescribe an official approach if/when one becomes available. I'd also love to just dump the code specific to this component, but it relies on a number of extensions/hacks that are spread across the SPM package that would be impractical to isolate just for the purpose of bundling a copy-paste solution to this answer.