Skip to content

Instantly share code, notes, and snippets.

@saschagordner
saschagordner / expanding-segmented-control.swift
Last active April 18, 2026 18:09
Expanding Segmented Control with Liquid Glass
// This gist shows how to use a `UISegmentedControl` to achieve the goal of having expandable segment items,
// where the active segment would show a label, while the others do not.
// Since `UISegmentedControl` only supports images *or* text for their items, we draw a custom image for the items,
// which is basically a HStack with a label and an optional label.
// I've used fixed widths for the items since otherwise the whole segment item would animate, leading to funky image
// resizing effects.
// This only serves as a demo and is not meant to be production ready.
@saschagordner
saschagordner / debug-frame.swift
Created December 29, 2024 10:58
SwiftUI Debug Frame
#if DEBUG
struct DebugFrameModifier: ViewModifier {
let color = Color.red
let lineWidth = 0.5
let spacing: CGFloat = 16
func body(content: Content) -> some View {
content
.border(color)
.overlay(