How to create a momentary segmented control in SwiftUI for macOS?

In AppKit, NSSegmentedControl has various styles defined by NSSegmentStyle and various tracking modes defined by NSSegmentSwitchTracking.

How can we set these properties in SwiftUI?

I'm currently using a Picker with the view modifier .pickerStyle(.segmented) applied but this seems to produce a segmented control with tracking set to "select one".

In particular I'm looking for momentary tracking so that I can create navigation-style buttons for backward/forward navigation.

Under AppKit, the canonical way to do this is an NSSegmentedControl of style separated and tracking momentary.

Is that possible under SwiftUI for macOS? (Using the latest versions of everything.)

Accepted Answer

@kennyc In SwiftUI you could accomplish this using a ControlGroup .

For example:

ControlGroup {
    Button("A") { }
    Button("B") { }
} label: {
    Label("Plus", systemImage: "plus")
}

The tracking behavior is implied by the kinds of controls you define in the group.

How to create a momentary segmented control in SwiftUI for macOS?
 
 
Q