GlassCard
Content container: opaque for dense content, glass when it floats above other content.
- Content
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-card
Content on an opaque, readable surface. Glass is kept for controls.
CaptureInstallation
spglass add glass-cardCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| 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
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. |
Media, header and footer
| Parameter | Type | Default | Meaning |
|---|---|---|---|
media | () -> some View | none | A photo, map or drawing shown edge to edge above the header and clipped to the card's rounded top. Give it a height. |
GlassCard(media:content:header:footer:) and GlassCard(media:content:) take the media area. The footer sits under a hairline and holds secondary text or one action. The surface carries a hairline and a contact shadow; a .floating card uses neutral glass (never the theme's glass tint) so that its text stays legible.
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
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.
Example
import SwiftUI
import SPGlassKit
public struct GlassCardExample: GlassExample {
public static let componentID = "glass-card"
@State private var openCount = 0
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
GlassCard("Monthly rent") {
Text("1,450 $").font(.title2)
Text("Sample listing · 4½ · Plateau").foregroundStyle(.secondary)
}
GlassCard {
Text("A long description wraps on several lines and stays readable because the card is opaque: dense text never sits on glass.")
} header: {
Label("About this place", systemImage: "text.alignleft")
} footer: {
Text("Fictitious data")
}
GlassCard {
// Any view: a photo, a map, a drawing. Give it a height.
Rectangle().fill(.tint.opacity(0.25)).frame(height: 120)
.overlay { Image(systemName: "building.2").font(.largeTitle).foregroundStyle(.tint) }
.accessibilityHidden(true)
} content: {
Text("Two bedrooms · 74 m² · Balcony").foregroundStyle(.secondary)
} header: {
Text("Loft on the canal")
} footer: {
Label("Available 1 July", systemImage: "calendar")
}
GlassCard(style: .floating, action: { openCount += 1 }) {
Label("3 listings nearby", systemImage: "mappin.and.ellipse")
Text("Opened \(openCount) times").font(.caption)
}
.accessibilityHint("Opens the list")
}
.padding()
}
}
}
#Preview("GlassCard") { GlassCardExample().glassTheme(.ocean) }
Registry entry
| Identifier | glass-card |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassCardStyle, GlassCard |
| Licence | MIT |
| Manifest | manifest.json |
Files
Components/Containers/GlassCard.swift9958 bytes · sha256 378dce583235…