Skip to content

Latest commit

 

History

History
95 lines (66 loc) · 1.63 KB

tailor-macos-windows-swiftui.md

File metadata and controls

95 lines (66 loc) · 1.63 KB

Tailor macOS windows with SwiftUI

Presenter: Haotian Zheng, SwiftUI Engineer

Link: https://developer.apple.com/wwdc24/10148

New SwiftUI APIs to tailor your macOS windows

Check out: Work with Windows in SwiftUI

Three main windows in example app structure

@main
struct DestinationVideo: App {
    var body: some Scene {
        WindowGroup(id: "catalog") {...}

        Window("About Destination Video", id: "about") {...}

        WindowGroup("Video Player", id: "player") {...}
    }
}

Style Toolbars

Remove title:

.toolbar(removing: title)

Remove toolbar background:

.toolbarBackgroundVisibility(.hidden, for: .windowToolbar)

Refine window behavior

Add container background:

.containerBackground(.thickMaterial, for: .window)

Customize the minimize behavior:

.windowMinimizeBehavior(.disabled)

Customize the restoration behavior:

.restorationBehavior(.disabled)

Adjust placement

Default placement:

.defaultWindowPlacement { content, context in
    var size = content.sizeThatFits(.unspecified)
    let displayBounds = context.defaultDisplay.visibleRect
    // modify size based on display bounds
    return WindowPlacement(size: size)
}

Ideal placement:

.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

.windowStyle(.plain)

Default launch behavior

.defaultLaunchBehavior(.presented)