NEW BOOK! SwiftUI Fundamentals: The essential guide to SwiftUI core concepts and APIs. Learn more ...NEW BOOK! SwiftUI Fundamentals:Master SwiftUI core concepts and APIs. Learn more...
Quick Tip Icon
Quick Tip

ControlGroup in context menus in SwiftUI

Starting from iOS 17 and iPadOS 17 we can now use a ControlGroup inside a contextMenu(), enabling more compact access to common actions.

Screenshot of a context menu open showing cut, copy and past all in a horizontal stack.
ContentView()
    .contextMenu {
        ControlGroup {
            Button {
                // cut action
            } label: {
                Label("Cut", systemImage: "scissors")
            }
            
            Button {
                // copy action
            } label: {
                Label("Copy", systemImage: "doc.on.doc")
            }
            
            Button {
                // paste action
            } label: {
                Label("Paste", systemImage: "doc.on.clipboard")
            }
        }
        
        Button(role: .destructive) {
            // delete action
        } label: {
            Label("Delete", systemImage: "trash")
        }
    }

On macOS this code creates a nested sub-menu with cut, copy and paste as items.

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

Deepen your understanding of SwiftUI!$35

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentalsby Natalia Panferova

  • Explore the key APIs and design patterns that form the foundation of SwiftUI
  • Develop a deep, practical understanding of how SwiftUI works under the hood
  • Learn from a former Apple engineer who worked on widely used SwiftUI APIs

Deepen your understanding of SwiftUI!

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

SwiftUI Fundamentals

by Natalia Panferova

$35