Declaration
compose().glassEffect(
glass?: SwiftUI.Glass,
options?: {
in?: SwiftUI.Shape;
}
)nonisolated func glassEffect(
_ glass: Glass = .regular,
in shape: some Shape = DefaultGlassEffectShape()
) -> some ViewParameters
glassSwiftUI.Glassoptions.inSwiftUI.Shape
Discussion
When you use a glass effect, the platform:
- Renders a shape anchored behind this view filled with the physical glass material
- Applies the foreground effects of the glass over this view.
For example, you could add a glass effect to a Label:
Label("Flag", systemImage: "flag.fill")
.padding()
.glassEffect()SwiftUI uses the Glass.regular variant by default along with
a Capsule shape.
SwiftUI anchors the glass to the view's bounds. For the example above, the physical glass material fills the entirety of the label's frame, which includes the padding.
You typically use this modifier with a GlassEffectContainer
to combine multiple glass shapes into a single shape that
can morph shapes into one another.
See also
More in Visual effects.
- allowedDynamicRangeReturns a new view configured with the specified allowed dynamic range.
- backgroundExtensionEffectAdds the background extension effect to the view. The view will be duplicated into mirrored copies which will be placed around the view on any edge with available safe area. Additionally, a blur effect will be applied on top to blur out the copies.
- blurApplies a Gaussian blur to this view.
- brightnessBrightens this view by the specified amount.
- clippedClips this view to its bounding rectangular frame.
- colorEffectReturns a new view that applies shader to self as a filter effect on the color of each pixel.
- colorInvertInverts the colors in this view.
- colorMultiplyAdds a color multiplication effect to this view.
- compositingGroupWraps this view in a compositing group.
- contrastSets the contrast and separation between similar colors in this view.
- distortionEffectReturns a new view that applies shader to self as a geometric distortion effect on the location of each pixel.
- drawingGroupComposites this view's contents into an offscreen image before final display.