Swift and SwiftUI Products Help Contact

SwiftUI MacOS Sheet buttons

Sheet dialog buttons don't meet the macOS human interface guidelines by default, I've tried some solutions in the past, but then I stumbled across a really simple way to do it and I'm sharing that now.

Ventura and Xcode 15.2. Published: June 3rd 2025

How NOT to do it

This simple solution, is a prime example of how NOT TO DO IT. The tiny "OK" button, doesn't just miss the Apple Human Interface Guidelines, it visually looks odd and lets the application down.

.sheet(isPresented: $showSheet, content: { VStack{ Text( "Hello World" ) Text( "This is a test of a toolbar in a sheet" ) Spacer() .frame( height: 20 ) HStack{ Spacer() Button( "Cancel", role: .cancel ) { showSheet = false } Button( "OK" ) { showSheet = false } .buttonStyle(.borderedProminent) } }.padding() }

Use a Toolbar...

Yes, it's that simple, use a toolbar and the placement attributes to specify which buttons perform which action and SwiftUI will not only place the buttons correctly, but will resize the default and cancel buttons to match the Apple Human Interface Guidelines.

.sheet(isPresented: $showSheet, content: { VStack{ Text( "Hello World" ) Text( "This is a test of a toolbar in a sheet" ) }.padding() .toolbar { ToolbarItem( placement: .confirmationAction ) { Button( "OK" ) { showSheet = false } } ToolbarItem( placement: .cancellationAction ) { Button( "Cancel" ) { showSheet = false } } ToolbarItem { if #available(macOS 14.0, *) { HelpLink { } } } } })

As a bonus tip, in this example we're showing the macOS Help Button in systems running macOS 14 or newer. The HelpLink isn't available on Ventura or lower.

  • Sleep Aid, our Mac Sleep troublshooter See what your Mac does when it should be asleep - Sleep Aid
  • Ohanaware © 2007 - 2025 Ohanaware Co., Ltd. Registered in Taiwan R.O.C. 🇹🇼
    Site managed by Strawberry Software's Lifeboat - running on DigitalOcean's platform.

    Pages

    Products Contact Weblog SwiftUI Promos

    Company

    About Us Environment Privacy Terms Update Plans

    Connect

    Bluesky Facebook Threads X / Twitter Mailing List