In SwiftUI for macOS, how do I configure a Picker as a segmented control to have a flexible width? This design pattern is present in Xcode 26 at the top of the sidebar and inspector panel.
I can't figure out the combination of view modifiers to achieve a similar look.
import SwiftUI
struct ContentView: View {
@State private var selection = 0
var body: some View {
VStack {
Picker("", selection: $selection) {
Image(systemName: "doc")
Image(systemName: "folder")
Image(systemName: "gear")
Image(systemName: "globe")
.frame(maxWidth: .infinity) // Doesn't do anything.
}
.labelsHidden()
.pickerStyle(.segmented)
.frame(maxWidth: .infinity) // Doesn't affect segment sizes.
Spacer()
}
}
}
I want the entire Picker to fill the width and for each segment to be of equal widths. How?
In AppKit I would use AutoLayout for the flexible width and NSSegmentedControl.segmentDistribution for the segment widths. Is there a SwiftUI equivalent?
macOS 26 / Xcode 26.3