GlassBadge
Count, value or status marker that never relies on colour alone.
- Content
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-badge
Content on an opaque, readable surface. Glass is kept for controls.
CaptureInstallation
spglass add glass-badgeCopies 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-badge |
|---|---|
| Module | SPGlassComponents |
| Kind | content-component — solid fill, no glass |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Feedback/GlassBadgeExample.swift |
Minimal usage
GlassBadge(count: unreadCount)Variants
| Variant | Appearance |
|---|---|
GlassBadge(count:cap:showsZero:tone:) | Number in a capsule; above cap it reads "99+"; hidden at zero unless showsZero. |
GlassBadge("New", tone:) | Short value in a capsule. |
GlassBadge(status: "Online", tone:) | Symbol in the tone's colour followed by the status name. |
Tones: .neutral, .accent, .success, .warning, .critical. Each status tone has a symbol of a different shape (circle, info.circle, checkmark.circle, exclamationmark.triangle, xmark.octagon).
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
count | Int | — | Number of items; negative values count as zero. |
cap | Int | 99 | Largest number shown; a cap below 1 counts as 1. |
showsZero | Bool | false | Shows "0" instead of hiding the badge. |
value | String | — | Short text; an empty string hides the badge. |
status | String | — | Status name, already localised by the host. |
showsLabel | Bool | true | false shows the status symbol alone. |
tone | GlassBadgeTone | .critical for counts, .neutral for values | Meaning and colour. |
GlassBadgeFormatter.countText(_:cap:showsZero:locale:) and countAccessibilityLabel(_:cap:) are pure and public.
Style and placement
| Parameter | Type | Default | Meaning |
|---|---|---|---|
style | GlassBadgeStyle | .solid (nil for a status badge) | .solid: filled with the tone's colour. .soft: a light tint with dark text, for labels repeated down a list or a table. .outline: a hairline on a clear background. A status badge with a style is enclosed in a pill. |
view.glassBadge(count:cap:showsZero:tone:) places a count badge on the top trailing corner of a view, typically an icon. GlassIconTile(systemImage:tone:size:) is the tinted rounded tile used next to a row, a banner or a timeline event; it is decorative and hidden from assistive technologies.
States
Hidden (count of zero, empty value) or visible. No interaction.
Advanced example
HStack {
Label("Inbox", systemImage: "tray")
Spacer()
GlassBadge(count: model.unread, cap: 999)
.accessibilityLabel("\(model.unread) unread messages")
}
GlassBadge(status: server.isHealthy ? "Operational" : "Outage", tone: server.isHealthy ? .success : .critical)Accessibility
- A count is read as "7 items", or "More than 99" above the cap; replace it with
.accessibilityLabelwhen the unit matters ("7 unread messages"). - A status badge is read by its label; the symbol is hidden from VoiceOver. With
showsLabel: falsethe label remains the accessibility label and the symbol shape still identifies the tone. - Text on a coloured fill uses
theme.onColor, the more legible of white and near-black for that fill. Digits follow the locale. - The caption font follows Dynamic Type.
Limits
- Never rely on the tone's colour for meaning: give a status badge a label, and a value badge a self-explanatory text.
- With the System theme (roles left to the system) a toned capsule uses a tinted surface with the primary text colour instead of a solid fill, because the contrast of white text on a system colour cannot be measured.
- A badge is not a button. Do not use it for long text: it does not wrap.
- For tab bars and list rows prefer the system
.badge(_:)modifier.
Example
import SwiftUI
import SPGlassKit
public struct GlassBadgeExample: GlassExample {
public static let componentID = "glass-badge"
@State private var unread = 7
public init() {}
public var body: some View {
VStack(alignment: .leading, spacing: 16) {
HStack(spacing: 12) {
Text("Inbox")
GlassBadge(count: unread)
Spacer()
Stepper("Unread", value: $unread, in: -1...150, step: 31).labelsHidden()
}
HStack(spacing: 12) {
GlassBadge("New", tone: .accent)
GlassBadge("Beta")
GlassBadge("−12 %", tone: .critical)
GlassBadge(count: 0, showsZero: true, tone: .neutral)
}
HStack(spacing: 12) {
GlassBadge("Paid", tone: .success, style: .soft)
GlassBadge("Due soon", tone: .warning, style: .soft)
GlassBadge("Draft", style: .outline)
GlassBadge(status: "Online", tone: .success, style: .soft)
}
Image(systemName: "bell")
.font(.title2)
.frame(width: 44, height: 44)
.glassBadge(count: unread)
.accessibilityLabel("Notifications")
VStack(alignment: .leading, spacing: 8) {
GlassBadge(status: "Online", tone: .success)
GlassBadge(status: "Degraded", tone: .warning)
GlassBadge(status: "Offline", tone: .critical)
GlassBadge(status: "Unknown", tone: .neutral)
}
}
.padding()
}
}
#Preview("GlassBadge") { GlassBadgeExample().glassTheme(.aurora) }
Registry entry
| Identifier | glass-badge |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-components-support, glass-forms-support, glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassBadgeStyle, GlassBadgeFormatter, GlassBadge |
| Licence | MIT |
| Manifest | manifest.json |
Files
Components/Feedback/GlassBadge.swift10134 bytes · sha256 9b122503c2c3…