SP GlassKit1.1.0

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.

GlassBadge 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-badge

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-badge
ModuleSPGlassComponents
Kindcontent-component — solid fill, no glass
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Feedback/GlassBadgeExample.swift

Minimal usage

Swift
GlassBadge(count: unreadCount)

Variants

VariantAppearance
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

ParameterTypeDefaultMeaning
countInt—Number of items; negative values count as zero.
capInt99Largest number shown; a cap below 1 counts as 1.
showsZeroBoolfalseShows "0" instead of hiding the badge.
valueString—Short text; an empty string hides the badge.
statusString—Status name, already localised by the host.
showsLabelBooltruefalse shows the status symbol alone.
toneGlassBadgeTone.critical for counts, .neutral for valuesMeaning and colour.

GlassBadgeFormatter.countText(_:cap:showsZero:locale:) and countAccessibilityLabel(_:cap:) are pure and public.

Style and placement

ParameterTypeDefaultMeaning
styleGlassBadgeStyle.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

Swift
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 .accessibilityLabel when the unit matters ("7 unread messages").
  • A status badge is read by its label; the symbol is hidden from VoiceOver. With showsLabel: false the 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

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

Identifierglass-badge
Version1.1.0
Depends onglass-components-support, glass-forms-support, glass-foundation
FrameworksSwiftUI
Public symbolsGlassBadgeStyle, GlassBadgeFormatter, GlassBadge
LicenceMIT
Manifestmanifest.json

Files