How it works
GlassBackgroundDisplayMode describes when a view's glass background material should appear. SwiftUI passes a value of this enumeration to the glassBackgroundEffect(displayMode:) modifier, letting you state whether the glass is rendered unconditionally or only when the system decides it's appropriate for the current context and platform. Reach for it when you want explicit control over the visibility of a glass surface rather than deferring entirely to automatic behavior, such as a panel that should always read as floating glass regardless of its surroundings.
Apply glass with glassBackgroundEffect(displayMode:)
The glassBackgroundEffect modifier draws the system glass material behind a view's content; its displayMode parameter takes a GlassBackgroundDisplayMode value that governs visibility. In the example the modifier wraps the padded VStack, turning that group of an Image and two Text views into a single glass panel.
Choose the visibility with the displayMode parameter
GlassBackgroundDisplayMode is the type of the displayMode: argument, so each of its cases selects a different rendering policy for the same glass effect. Here the call site supplies .displayMode and resolves which case to use against that enumeration.
Force the material on with the always case
The always case renders the glass background unconditionally, so the surface appears whether or not the system would otherwise suppress it. The example writes .glassBackgroundEffect(displayMode: .always) so the panel keeps its always-on glass look in every context.
Let the system decide with the implicit case
GlassBackgroundDisplayMode also offers an implicit policy that defers to the platform, showing the glass only when SwiftUI determines it suits the environment. Swapping .always for .implicit on the same glassBackgroundEffect call hands that judgment back to the framework.
Pad the content so the material has room to read
Because the glass is drawn behind whatever it modifies, the inner .padding(24) gives the Image and Text content breathing space inside the panel while the trailing .padding() insets the whole glass surface from its container. The GlassBackgroundDisplayMode value still controls only whether that material is shown, not its layout.
Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct GlassBackgroundDisplayModeDemo: View {
var body: some View {
VStack(spacing: 12) {
Image(systemName: "sparkles")
.font(.largeTitle)
Text("Glass Panel")
.font(.headline)
Text("Always-on glass background")
.font(.caption)
.foregroundStyle(.secondary)
}
.padding(24)
.glassBackgroundEffect(displayMode: .always)
.padding()
}
}