Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2024 SwiftUI & UI Frameworks

WWDC24 · 11 min · SwiftUI & UI Frameworks

Tailor macOS windows with SwiftUI

Make your windows feel tailor-made for macOS. Fine-tune your app’s windows for focused purposes, ease of use, and to express functionality. Use SwiftUI to style window toolbars and backgrounds. Arrange your windows with precision, and make smart decisions about restoration and minimization.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

  • 0:53 — Anatomy of a window
  • 1:53 — App window structure
  • 2:41 — Style window toolbars
  • 3:53 — Refine window behaviors
  • 5:55 — Adjust window placement

Code shown on screen · 9 snippets

Style Toolbars - Removing Title swift · at 3:11 ↗
.toolbar(removing: title)
Style Toolbars - Removing Toolbar Background swift · at 3:14 ↗
.toolbarBackgroundVisibility(.hidden, for: .windowToolbar)
Refine Behaviors - Adding Container Background swift · at 4:33 ↗
.containerBackground(.thickMaterial, for: .window)
Refine Behaviors - Minimize Behavior swift · at 5:13 ↗
.windowMinimizeBehavior(.disabled)
Refine Behaviors - Restoration Behavior swift · at 5:44 ↗
.restorationBehavior(.disabled)
Adjust Placement - Default Placement swift · at 7:11 ↗
.defaultWindowPlacement { content, context in
    var size = content.sizeThatFits(.unspecified)
    let displayBounds = context.defaultDisplay.visibleRect
    // modify size based on display bounds
    return WindowPlacement(size: size)
}
Adjust Placement - Ideal Placement swift · at 8:35 ↗
.windowIdealPlacement { content, context in
    var size = content.sizeThatFits(.unspecified)
    let displayBounds = context.defaultDisplay.visibleRect
    // modify size based on display bounds
    return WindowPlacement(size: size)
}
Borderless Window swift · at 9:48 ↗
.windowStyle(.plain)
Default Launch Behavior swift · at 9:53 ↗
.defaultLaunchBehavior(.presented)

Resources