| name | swiftui-design-principles |
| description | Design principles for building polished, native-feeling SwiftUI apps and widgets. Use this skill when creating or modifying SwiftUI views, iOS widgets (WidgetKit), or any native Apple UI. Ensures proper spacing, typography, colors, and widget implementations that look and feel like quality apps rather than AI-generated slop. |
| license | MIT |
| metadata | {"author":"arjitj2","version":"1.1.1"} |
This skill encodes design principles derived from comparing polished, production-quality SwiftUI apps against poorly-built ones. The patterns here represent what separates an app that feels "right" from one where the margins, spacing, and text sizes just look "off."
Apply these principles whenever building or modifying SwiftUI interfaces, WidgetKit widgets, or any native Apple UI.
Core Philosophy
Restraint over decoration. Every pixel must earn its place. A polished app uses fewer colors, fewer font sizes, fewer spacing values, and fewer words — but uses them consistently. Over-engineering visual elements (custom gradients, decorative borders, bespoke dividers) creates visual noise. Native components and system colors create harmony.
Attention is scarce. Keep UI copy shorter than you think it needs to be. Prefer one clear headline and one compact supporting block over repeated explanation in the title, subtitle, body, and footer. If a screen needs rationale, put it in one purposeful place instead of scattering it across the page.
1. Spacing System: Use a Consistent Grid
CRITICAL: Use spacing values from a base-4/base-8 grid. Never use arbitrary values.
Allowed spacing values
4, 8, 12, 16, 20, 24, 32, 40, 48
Bad (arbitrary values that create visual dissonance)
.padding(.bottom, 26)
.padding(.bottom, 34)
.padding(.bottom, 36)
HStack(spacing: 18)
.padding(14)
Good (values from a consistent grid)
.padding(.horizontal, 20)
.padding(.top, 8)
Spacer().frame(height: 32)
HStack(spacing: 4)
.padding(.vertical, 12)
.padding(.horizontal, 16)
Standard padding assignments
- Outer content padding: 16-20pt horizontal
- Between major sections: 24-32pt vertical
- Within grouped components: 4-12pt
- Card/row internal padding: 12-16pt vertical, 16pt horizontal
2. Typography: Hierarchy Through Weight, Not Just Size
The principle
Use fewer font sizes with clear weight differentiation. Lighter weights at larger sizes; medium/regular at smaller sizes. This creates sophistication rather than visual chaos.
Recommended type scale (for a data-focused app)
| Role | Size | Weight | Notes |
|---|
| Hero number | 36-42pt | .light | Large but visually light -- elegant, not heavy |
| Secondary stat | 20-24pt | .light | Same weight family as hero, smaller |
| Body / toggle label | 15pt | .regular | Standard iOS body size |
| Section header (uppercase) | 11pt | .medium | With tracking/letter-spacing |
| Caption / subtitle | 11-13pt | .regular | Secondary information |
Bad (too many sizes, inconsistent weights)
.font(.system(size: 60, weight: .ultraLight))
.font(.system(size: 44, weight: .regular))
.font(.system(size: 31, weight: .ultraLight))
.font(.system(size: 18, weight: .regular))
.font(.system(size: 14, weight: .regular))
.font(.system(size: 13, weight: .regular))
.font(.system(size: 12, weight: .regular))
Good (clear hierarchy, fewer sizes)
.font(.system(size: 42, weight: .light, design: .monospaced))
.font(.system(size: 24, weight: .light, design: .monospaced))
.font(.system(size: 15, weight: .regular, design: .monospaced))
.font(.system(size: 14, weight: .regular, design: .monospaced))
.font(.system(size: 11, weight: .medium, design: .monospaced))
Font design consistency
Pick ONE font design and use it everywhere -- app AND widgets:
design: .monospaced
Letter spacing (tracking)
Use at most 2 values, and only on uppercase labels:
.tracking(1.5)
.tracking(3)
Never use 3+ different tracking values like kerning(4), kerning(4.5), kerning(5) -- the differences are imperceptible but the inconsistency registers subconsciously.
Numeric formatting for identifiers
Years and other fixed identifiers should not be locale-grouped.
Text(String(year))
Text(year, format: .number.grouping(.never))
Text("\(year)")
3. Colors: System Semantic Colors Over Hardcoded Values
The principle
Use SwiftUI's semantic color system. It automatically handles light/dark mode, accessibility, and looks native. Hardcoded colors with manual opacity values create maintenance nightmares and look artificial.
Bad (hardcoded white with a dozen opacity values)
Color.black.ignoresSafeArea()
Color.white.opacity(0.08)
Color.white.opacity(0.09)
Color.white.opacity(0.3)
Color.white.opacity(0.32)
Color.white.opacity(0.42)
Color.white.opacity(0.44)
Color.white.opacity(0.72)
Color.white.opacity(0.88)
Color.white.opacity(0.9)
Color.white.opacity(0.94)
Good (semantic system colors)
Color(.systemBackground)
Color(.secondarySystemBackground)
Color(.separator)
Color.primary
.foregroundStyle(.secondary)
.foregroundStyle(.tertiary)
When you do need opacity
Limit to 2-3 values with clear purposes:
.opacity(0.15)
.opacity(0.3)
4. Component Sizing: Proportional, Not Oversized
Progress rings / circular indicators
.frame(width: 200, height: 200)
Circle().stroke(..., lineWidth: 3)
.frame(width: 90, height: 90)
Circle().stroke(..., lineWidth: 3)
.frame(width: 260, height: 260)
Circle().stroke(..., lineWidth: 9)
Circle().stroke(..., lineWidth: 8)
Stroke width consistency
Always use the same lineWidth for background and foreground strokes of the same element:
Circle().stroke(background, lineWidth: 3)
Circle().trim(from: 0, to: fraction).stroke(fill, lineWidth: 3)
Circle().stroke(background, lineWidth: 9)
Circle().trim(from: 0, to: fraction).stroke(fill, lineWidth: 8)
List rows and toggle rows
Toggle(isOn: $value) {
Text(title)
.font(.system(size: 15, weight: .regular, design: .monospaced))
}
.padding(.horizontal, 16)
.padding(.vertical, 12)
HStack {
Text(label)
.font(.system(size: 18))
Spacer()
Toggle("", isOn: $isOn)
.labelsHidden()
}
.frame(height: 70)
5. Grouped Content & Cards: Use System Patterns
Bad (over-engineered custom card)
VStack { ... }
.padding(.vertical, 4)
.background(
RoundedRectangle(cornerRadius: 22)
.fill(LinearGradient(
colors: [Color(white: 0.10), Color(white: 0.085)],
startPoint: .topLeading, endPoint: .bottomTrailing
))
)
.overlay(
RoundedRectangle(cornerRadius: 22)
.stroke(Color.white.opacity(0.08), lineWidth: 1)
)
Good (native grouped style)
VStack(spacing: 0) {
row1
Divider().padding(.leading, 16)
row2
Divider().padding(.leading, 16)
row3
}
.background(Color(.secondarySystemBackground))
.clipShape(.rect(cornerRadius: 10))
Key rules for grouped content
- Corner radius: 10pt for cards/groups (matches iOS system style). Never 22pt+.
- Dividers: Use the system
Divider() with .padding(.leading, 16) for iOS-standard inset. Never build custom divider structs.
- Card padding: 12-16pt vertical, 16pt horizontal. Never 4pt vertical.
- Background:
Color(.secondarySystemBackground) -- never custom gradients for standard cards.
6. Navigation: Use NavigationStack
NavigationStack {
ScrollView {
content
}
.toolbar {
ToolbarItem(placement: .principal) {
Text("Title")
.font(.system(size: 13, weight: .medium, design: .monospaced))
.tracking(3)
.foregroundStyle(.tertiary)
}
}
.navigationBarTitleDisplayMode(.inline)
}
ZStack {
Color.black.ignoresSafeArea()
ScrollView {
VStack {
Text("2026").font(...)
content
}
}
}
7. WidgetKit: Use Native Components
Circular lock screen widget
Gauge(value: entry.fraction) {
Text("")
} currentValueLabel: {
Text("\(Int(entry.percentage))%")
.font(.system(size: 12, weight: .medium, design: .monospaced))
}
.gaugeStyle(.accessoryCircular)
.containerBackground(.fill.tertiary, for: .widget)
ZStack {
Circle().stroke(Color.primary.opacity(0.18), lineWidth: 4)
Circle().trim(from: 0, to: progress).stroke(...)
Text(percentText)
.font(.system(size: 14, weight: .bold, design: .rounded))
}
Rectangular lock screen widget
VStack(alignment: .leading, spacing: 4) {
HStack {
Text(year).font(.system(size: 13, weight: .semibold, design: .monospaced))
Spacer()
Text(percentage).font(.system(size: 13, weight: .medium, design: .monospaced))
.foregroundStyle(.secondary)
}
Gauge(value: fraction) { Text("") }
.gaugeStyle(.linearCapacity)
.tint(.primary)
HStack {
Spacer()
Text("\(dayOfYear)/\(totalDays)")
.font(.system(size: 11, weight: .regular, design: .monospaced))
.foregroundStyle(.secondary)
}
}
.containerBackground(.fill.tertiary, for: .widget)
GeometryReader { proxy in
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 2).fill(Color.primary.opacity(0.16))
RoundedRectangle(cornerRadius: 2).fill(Color.primary)
.frame(width: max(2, proxy.size.width * progress))
}
}
.frame(height: 6)
Widget background
.containerBackground(.fill.tertiary, for: .widget)
.containerBackground(.black, for: .widget)
Widget family coverage
Support all relevant families -- don't skip common ones:
.supportedFamilies([
.accessoryCircular,
.accessoryRectangular,
.accessoryInline,
.systemSmall,
.systemMedium,
.systemLarge,
])
Cross-family visual consistency
Medium and large home widgets should share the same structural layout:
- Header: year on the left, percentage on the right
- Middle: progress bar
- Footer:
day/total right aligned
Do not re-invent hierarchy per family unless there is a hard size constraint.
Always include explicit internal padding on home widgets to avoid clipping near rounded edges:
.padding(.horizontal, 12)
.padding(.vertical, 12)
Widget memory budget (hard limit)
Widget extensions have a tight memory budget (commonly around 30 MB). Dense visualizations can be killed by EXC_RESOURCE if built from too many nested views.
Canvas { context, size in
}
LazyVGrid(columns: columns) {
ForEach(1...366, id: \.self) { day in
ZStack { Circle(); partialFillLayer }
}
}
Timeline refresh (match data granularity)
let tomorrow = calendar.startOfDay(for: calendar.date(byAdding: .day, value: 1, to: now)!)
Timeline(entries: [entry], policy: .after(tomorrow))
let refresh = Calendar.current.date(byAdding: .minute, value: 15, to: now)!
Timeline(entries: [entry], policy: .after(refresh))
let tooFrequent = Calendar.current.date(byAdding: .minute, value: 1, to: now)!
Timeline(entries: [entry], policy: .after(tooFrequent))
8. Interactive Elements
Toggles
Toggle(isOn: $value) {
Text(title)
.font(.system(size: 15, weight: .regular, design: .monospaced))
}
.tint(.green)
HStack {
Text(label).font(.system(size: 18))
Spacer()
Toggle("", isOn: $isOn)
.labelsHidden()
.tint(Color.white.opacity(0.44))
}
Mutually exclusive options
When options are exclusive (e.g. daily/weekly/monthly cadence), use one selected value, not three independent toggles.
enum Cadence: String, CaseIterable { case daily, weekly, monthly }
@State private var cadence: Cadence = .daily
ForEach(Cadence.allCases, id: \.rawValue) { option in
Button {
cadence = option
} label: {
HStack {
Image(systemName: cadence == option ? "checkmark.circle.fill" : "circle")
Text(option.rawValue.capitalized)
}
}
}
Button("Preview") { sendPreview() }
Toggle("Daily", isOn: $daily)
Toggle("Weekly", isOn: $weekly)
Toggle("Monthly", isOn: $monthly)
Animated transitions for changing numbers
Text(String(format: "%.2f", percentage))
.contentTransition(.numericText())
9. Interactive Editors: Centralize Geometry and State
Interactive editors (collages, crops, canvases, media framing tools, layout pickers) need stricter state and layout discipline than ordinary forms.
Presentation state
Present editor flows from payload state, not from a separate Bool plus independently-managed data.
@State private var activeCropRequest: CropRequest?
.sheet(item: $activeCropRequest) { request in
CropEditor(request: request)
}
@State private var showCropEditor = false
@State private var selectedImage: UIImage?
.sheet(isPresented: $showCropEditor) {
if let selectedImage { CropEditor(image: selectedImage) }
}
Shared geometry model
If the app previews pan/zoom/crop/layout live and later exports the result, use one shared geometry model for both preview and render.
let normalized = EditorGeometry.normalizedAdjustment(adjustment, imageSize: image.size, slotSize: slotSize)
let drawRect = EditorGeometry.drawRect(for: image.size, in: slotRect, adjustment: adjustment)
let previewOffset = ...
let exportOffset = ...
If a user can zoom out enough to reveal background, that must be an intentional part of the shared geometry model, not an editor-only exception.
Gesture coordination
Tap, long-press-drag, and pinch are not independent features. In SwiftUI they compete unless you model their relationship explicitly.
- Use a single interaction state for the active tile/card/canvas item.
- Decide which gesture has priority and which ones should run simultaneously.
- Reset temporary gesture state deliberately when selection changes.
- Prefer one coherent state machine over scattered booleans tied to individual gestures.
Fixed editor layout
If the screen must not scroll, budget vertical space top-down using a few named regions:
- header
- canvas stage
- settings region
- bottom toolbar
Keep that sizing math in one place. Don't let each subview invent its own height.
Custom headers and safe areas
If you replace the system navigation bar with a custom header:
- Be explicit about whether the parent already respects the safe area.
- Do not add
safeAreaInsets.top reflexively; double-counting it creates obvious dead space.
- Keep custom headers compact. They should feel like navigation chrome, not a full content section.
Settings surfaces
When an editor has several configuration modes (Layout, Border, Ratio, Background, etc.), show one active settings surface at a time instead of stacking every control on screen.
This keeps the canvas visually dominant and makes each control group easier to understand.
10. Data Model: Share Between App and Widgets
struct YearProgress {
static func current() -> YearProgress { ... }
}
let dayProgress = elapsedInCurrentDay / totalSecondsInDay
let elapsedDays = Double(dayOfYear - 1) + dayProgress
let fraction = elapsedDays / Double(totalDays)
struct YearProgressSnapshot { ... }
struct YearProgressWidgetSnapshot { ... }
11. Quick Checklist
Before shipping any SwiftUI view, verify: