SP GlassKit1.1.0

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.

GlassCard running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-card

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-card
ModuleSPGlassComponents
Kindcontent-component — opaque themed surface by default; Liquid Glass only in the .floating style
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Containers/GlassCardExample.swift

Minimal usage

Swift
GlassCard("Monthly rent") {
    Text("1,450 $").font(.title2)
}

Variants

VariantUse
.opaque (default)Dense content: text, figures, forms. Drawn with glassOpaqueSurface.
.floatingA 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 / footerOptional slots: the header uses the headline font and the header trait, the footer the caption font.

Parameters

ParameterTypeDefaultMeaning
titleKey / verbatimLocalizedStringKey / StringProtocol—Title used as the header.
styleGlassCardStyle.opaqueSurface of the card.
paddingGlassSpacingStep.mdInner padding from the theme's spacing scale.
action(@MainActor () -> Void)?nilMakes the card a button.
content@ViewBuilder—Body of the card.
header, footer@ViewBuildernoneOptional slots.
ParameterTypeDefaultMeaning
media() -> some ViewnoneA 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

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 .floating for 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

Complete example (compiled with the package)
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

Identifierglass-card
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassCardStyle, GlassCard
LicenceMIT
Manifestmanifest.json

Files