GlassButton
Button using the system glass styles, with destructive role, loading and disabled states.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-button
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-buttonCopies 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-button |
|---|---|
| Module | SPGlassComponents |
| Kind | native-wrapper — the system draws the button with .buttonStyle(.glass) or .glassProminent |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Buttons/GlassButtonExample.swift |
Minimal usage
GlassButton("Save") { save() }Variants
| Variant | Use |
|---|---|
.regular | Most actions. Untinted system glass. |
.prominent | The main action of a view, filled with the theme's primary colour. One per view at most. |
role: .destructive | Deletion and other irreversible actions. Tinted with the theme's destructive colour; the system also announces the role. |
Sizes are .small, .regular and .large; they map to the system ControlSize, so the button keeps the metrics of the platform.
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
titleKey | LocalizedStringKey | — | Title, looked up in the host application's strings. |
verbatim | StringProtocol | — | Title that is already a string (data, user content). |
systemImage | String? | nil | SF Symbol shown before the title. Hidden while loading. |
variant | GlassButtonVariant | .regular | Visual weight. |
role | ButtonRole? | nil | System role (.destructive, .cancel). |
size | GlassControlSize | .regular | Control size. |
isLoading | Bool | false | Shows a progress indicator and ignores taps. |
action | @MainActor () -> Void | — | Called on activation. |
label | @ViewBuilder | — | Custom label, instead of a title. |
States
Idle, pressed and focused are drawn by the system. disabled is the standard .disabled(_:) modifier. loading is isLoading: the action cannot be triggered and VoiceOver reads "Loading" as the value of the button.
Advanced example
GlassButton(variant: .prominent, size: .large, isLoading: model.isUploading) {
model.upload()
} label: {
VStack(alignment: .leading) {
Text("Upload")
Text(model.fileName).font(.caption)
}
}
.keyboardShortcut(.defaultAction)Accessibility
- The title is the accessibility label; a custom label must contain text or set
.accessibilityLabel. - The label of a prominent button stays legible on a light fill: when the theme's
primary(ordestructive) colour is pale in the current appearance, as in Obsidian's dark appearance, the label takes a near-black instead of the system's white (GlassButtonContrastholds the rule: white is kept while its contrast on the fill is at least 2.5).glassButtonLabelContrast(_:role:)applies the same rule to a label of your own. - Text follows Dynamic Type and wraps instead of truncating.
- The loading state is exposed as an accessibility value, not by the spinner alone.
- The destructive role is conveyed by the system role, not only by colour.
Limits
- The glass itself (blur, refraction, highlights) is drawn by the system and cannot be configured.
- A simulated Reduce Transparency (
glassSimulatedAccessibility) switches to the bordered system styles; the real setting is handled by the system inside the glass styles. - Several prominent buttons side by side weaken the hierarchy; prefer one.
Example
import SwiftUI
import SPGlassKit
public struct GlassButtonExample: GlassExample {
public static let componentID = "glass-button"
@State private var isSaving = false
@State private var saveCount = 0
public init() {}
public var body: some View {
VStack(spacing: 16) {
GlassButton("Save changes", systemImage: "checkmark", variant: .prominent, isLoading: isSaving) {
isSaving = true
saveCount += 1
}
GlassButton("Duplicate", systemImage: "plus.square.on.square") { saveCount += 1 }
GlassButton("Delete draft", systemImage: "trash", role: .destructive) { saveCount = 0 }
GlassButton("Unavailable", size: .small) {}
.disabled(true)
GlassButton(variant: .regular, size: .large) {
isSaving = false
} label: {
VStack {
Text("Reset")
Text("Saved \(saveCount) times").font(.caption)
}
}
}
.padding()
}
}
#Preview("GlassButton") { GlassButtonExample().glassTheme(.aurora) }
Registry entry
| Identifier | glass-button |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-components-support, glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassButton, GlassButtonLabel |
| Licence | MIT |
| Manifest | manifest.json |
Files
Components/Buttons/GlassButton.swift5326 bytes · sha256 3acb39de5e38…