GlassCard
| Identifier | glass-card |
| Module | SPGlassComponents |
| Kind | content-component — opaque themed surface by default; Liquid Glass only in the .floating style |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Containers/GlassCardExample.swift |
Minimal usage
swift
GlassCard("Monthly rent") {
Text("1,450 $").font(.title2)
}Variants
| Variant | Use |
|---|---|
.opaque (default) |
Dense content: text, figures, forms. Drawn with glassOpaqueSurface. |
.floating |
A card above other content (a map, a photo, a feed). Drawn with glassSurface; the glass is interactive only when the card has an action. |
action: |
The whole card becomes one button. |
| header / footer | Optional slots: the header uses the headline font and the header trait, the footer the caption font. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
titleKey / verbatim |
LocalizedStringKey / StringProtocol |
— | Title used as the header. |
style |
GlassCardStyle |
.opaque |
Surface of the card. |
padding |
GlassSpacingStep |
.md |
Inner padding from the theme's spacing scale. |
action |
(@MainActor () -> Void)? |
nil |
Makes the card a button. |
content |
@ViewBuilder |
— | Body of the card. |
header, footer |
@ViewBuilder |
none | Optional slots. |
States
Without an action the card has no state. With an action, pressed and focused are drawn by the system button; .disabled(_:) applies as usual.
Advanced example
swift
GlassCard(style: .floating, action: { router.open(listing) }) {
Text(listing.address)
Text(listing.price, format: .currency(code: "CAD"))
} header: {
Label("Nearby", systemImage: "mappin.and.ellipse")
} footer: {
Text(listing.updated, format: .relative(presentation: .named))
}
.accessibilityHint("Opens the listing")Accessibility
- A tappable card is a single
Button: VoiceOver reads its texts as one element with the button trait. - A static card is a container; its header carries the header trait, so rotor navigation by headings works.
- Text uses theme fonts and wraps; the card grows with Dynamic Type.
Limits
- Do not put buttons, links or fields inside a card that has an
action; nested controls are not reachable separately. - Do not use
.floatingfor long text, and never place a floating card inside another glass surface. - The card takes the width of its content; give it
.frame(maxWidth: .infinity, alignment: .leading)to fill a column.