Compose beautiful preference panels.
Setting is available via the Swift Package Manager. Requires iOS 15+ or macOS Monterey and up.
https://github.com/aheze/Setting
import Setting
import SwiftUI
struct PlaygroundView: View {
/// Setting supports `@State`, `@AppStorage`, `@Published`, and more!
@AppStorage("isOn") var isOn = true
var body: some View {
/// Start things off with `SettingStack`.
SettingStack {
/// This is the main settings page.
SettingPage(title: "Playground") {
/// Use groups to group components together.
SettingGroup(header: "Main Group") {
/// Use any of the pre-made components...
SettingToggle(title: "This value is persisted!", isOn: $isOn)
/// ...or define your own ones!
SettingCustomView {
Image("Logo")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 160)
.padding(20)
}
/// Nest `SettingPage` inside other `SettingPage`s!
SettingPage(title: "Advanced Settings") {
SettingText(title: "I show up on the next page!")
}
}
}
}
}
}
View more examples in the example app.
|
|
|
|
|
|
|
|
|
|
id
parameter to make sure everything gets rendered correctly.SettingText(id: "Announcement 1", title: "Hello!")
SettingText(id: "Announcement 2", title: "Hello!")
if-else
support!SettingToggle(title: "Turn on", isOn: $isOn)
if isOn {
SettingText("I'm turned on!")
}
SettingCustomView
to style them.SettingCustomView {
SettingText(title: "I'm bold!")
.bold()
}
Need to store custom structs in AppStorage
? Check out @IanKeen's awesome gist!
You can pass in a custom SettingViewModel
instance for finer control.
|
|
Author | Contributing | Need Help? |
---|---|---|
Setting is made by aheze. | All contributions are welcome. Just fork the repo, then make a pull request. | Open an issue or join the Discord server. You can also ping me on Twitter. |
MIT License
Copyright (c) 2023 A. Zheng
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
link |
Stars: 963 |
Last commit: 7 hours ago |
Introducing Setting, a library for composing beautiful preference panels.
Looking to add a Settings view to your app? Look no further!
Want to upgrade your current Settings view? You're in luck.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics