GlassBanner
| Identifier | glass-banner |
| Module | SPGlassComponents |
| Kind | content-component — opaque surface tinted with the severity colour; no glass |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Feedback/GlassBannerExample.swift |
Minimal usage
GlassBanner(.success, title: "Payment received")Variants
| Severity | Symbol | Word | Theme role |
|---|---|---|---|
.information |
info.circle.fill |
Information | accent |
.success |
checkmark.circle.fill |
Success | success |
.warning |
exclamationmark.triangle.fill |
Warning | warning |
.error |
xmark.octagon.fill |
Error | destructive |
Each severity is shown three ways: a symbol of a distinct shape, its name in text, and the tint. Options: message, action, onDismiss.
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
severity |
GlassBannerSeverity |
— | See Variants. |
title |
LocalizedStringKey, verbatim: string or Text |
— | Main line. |
message |
String? (or Text?) |
nil |
Detail, shown as is. |
action |
GlassBannerAction? |
nil |
One button (GlassBannerAction("Retry") { … } or verbatim:). |
onDismiss |
(@MainActor () -> Void)? |
nil |
Shows a dismiss button. |
States
The banner is stateless: the host shows or removes it. It stays in the layout (it is not transient like a toast).
Colours come from GlassTintedColors.resolve(tint:surface:text:): the background is the theme surface mixed with 14 % of the severity colour; the text is the theme's primary text colour when it reaches 4.5:1 against that background, otherwise black or white; the symbol and outline use the severity colour when it reaches 3:1, otherwise the text colour. Tests check these ratios for every built-in theme in light and dark.
Advanced example
if let failure = model.syncFailure {
GlassBanner(.error, verbatim: failure.localizedDescription,
message: failure.recoverySuggestion,
action: GlassBannerAction("Retry") { model.sync() },
onDismiss: { model.syncFailure = nil })
.transition(.opacity)
}Accessibility
- VoiceOver reads the severity word, the title and the message as one element; the symbol is hidden because the word says the same thing.
- The action and dismiss buttons are separate elements with labels and the minimum hit target; the action is underlined so that it is recognisable without colour.
- Text wraps and follows Dynamic Type; the symbol aligns to the top so long messages stay readable.
- For an error that appears while the user is elsewhere on screen, also post an announcement or move focus: the banner does not announce itself.
Limits
- With the System theme (roles left to the system) colours cannot be measured: the background is mixed by SwiftUI and text and symbol use the primary label colour.
- One action at most. For several choices use a
GlassAlert. - The severity word is GlassKit's (English and French); the title and message are the host's.