How to build a settings interface with SettingStack
mainTo create a settings interface, start with a SettingStack. Inside the stack, use SettingPage to define pages. You can nest SettingPage components inside each other to create hierarchical navigation. Use SettingGroup to organize components within a page. The syntax is powered by result builders, allowing for a declarative structure.
import Setting
import SwiftUI
struct PlaygroundView: View {
@AppStorage("isOn") var isOn = true
var body: some View {
SettingStack {
SettingPage(title: "Playground") {
SettingGroup(header: "Main Group") {
SettingToggle(title: "This value is persisted!", isOn: $isOn)
SettingCustomView {
Image("Logo")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 160)
.padding(20)
}
SettingPage(title: "Advanced Settings") {
SettingText(title: "I show up on the next page!")
}
}
}
}
}
}