Create SwiftUI settings panes
mainFor macOS 10.15 or later, you can create panes using SwiftUI. Use Settings.Pane to define the pane's identity and content. To achieve standard macOS alignment, use the bundled Settings.Container and Settings.Section components, or the .settingDescription() view modifier.
To use SwiftUI panes alongside AppKit NSViewController panes, wrap the SwiftUI Settings.Pane in a Settings.PaneHostingController and pass that to the SettingsWindowController.
struct CustomPane: View {
var body: some View {
Settings.Container(contentWidth: 450.0) {
Settings.Section(title: "Section Title") {
// Some view.
}
Settings.Section(label: {
// Custom label aligned on the right side.
}) {
// Some view.
}
}
}
}
// Wrapping for AppKit compatibility:
let CustomViewSettingsPaneViewController: () -> SettingsPane = {
let paneView = Settings.Pane(
identifier: …,
title: …,
toolbarIcon: NSImage(…)
) {
CustomPane()
}
return Settings.PaneHostingController(paneView: paneView)
}