Contents

glassEffect(_:in:)

Applies the Liquid Glass effect to a view.

Declaration

nonisolated func glassEffect(_ glass: Glass = .regular, in shape: some Shape = DefaultGlassEffectShape()) -> some View

Mentioned in

Discussion

When you use this effect, the system:

  • Renders a shape anchored behind a view with the Liquid Glass material.

  • Applies the foreground effects of Liquid Glass over a view.

For example, to add this effect to a Text:

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect()

SwiftUI uses the regular variant by default along with a Capsule shape.

SwiftUI anchors the Liquid Glass to a view’s bounds. For the example above, the material fills the entirety of the Text frame, which includes the padding.

You typically use this modifier with a GlassEffectContainer to combine multiple Liquid Glass shapes into a single shape that can morph into one another.

See Also

Styling views with Liquid Glass