- Notifications
You must be signed in to change notification settings - Fork71
Compose beautiful preference panels.
License
NotificationsYou must be signed in to change notification settings
aheze/Setting
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Compose beautiful preference panels.
- Simple but powerful syntax (powered byresult builders).
- Create nested pages and groups.
- Fully searchable.
- Native integration with SwiftUI and AppStorage.
- Comes with pre-made components: Toggle, Button, Slider, etc...
- Style components with native SwiftUI modifiers.
- Show and hide components dynamically.
- Add your own custom SwiftUI views.
- Works on iOS and macOS.
Setting is available via theSwift Package Manager. Requires iOS 15+ or macOS Monterey and up.
https://github.com/aheze/Setting
import Settingimport SwiftUIstructPlaygroundView:View{ /// Setting supports `@State`, `@AppStorage`, `@Published`, and more!@AppStorage("isOn")varisOn=truevarbody:someView{ /// 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 theexample app.
structPlaygroundView:View{varbody:someView{SettingStack{SettingPage(title:"Playground"){SettingGroup{SettingText(title:"Hello!")}}}}} |
SettingStack{SettingPage(title:"Playground"){SettingGroup{SettingText(title:"Hello!")}SettingGroup{SettingPage(title:"First Page"){}.previewIcon("star")SettingPage(title:"Second Page"){}.previewIcon("sparkles")SettingPage(title:"Third Page"){}.previewIcon("leaf.fill")}}} |
structPlaygroundView:View{@AppStorage("isOn")varisOn=true@AppStorage("value")varvalue=Double(5)varbody:someView{SettingStack{SettingPage(title:"Playground"){SettingGroup{SettingToggle(title:"On", isOn: $isOn)}SettingGroup(header:"Slider"){SettingSlider( value: $value, range:0...10)}}}}} |
structPlaygroundView:View{@AppStorage("index")varindex=0varbody:someView{SettingStack{SettingPage(title:"Playground"){SettingGroup{SettingPicker( title:"Picker", choices:["A","B","C","D"], selectedIndex: $index)SettingPicker( title:"Picker with menu", choices:["A","B","C","D"], selectedIndex: $index, choicesConfiguration:.init( pickerDisplayMode:.menu))}}}}} |
SettingStack{SettingPage(title:"Playground"){SettingCustomView{Color.blue.opacity(0.1).cornerRadius(12).overlay{Text("Put anything here!").foregroundColor(.blue).font(.title.bold())}.frame(height:150).padding(.horizontal,16)}}} |
- If multiple components have the same title, use the
id
parameter to make sure everything gets rendered correctly.
SettingText(id:"Announcement 1", title:"Hello!")SettingText(id:"Announcement 2", title:"Hello!")
- Setting comes with
if-else
support!
SettingToggle(title:"Turn on", isOn: $isOn)if isOn{SettingText("I'm turned on!")}
- Wrap components in
SettingCustomView
to style them.
SettingCustomView{SettingText(title:"I'm bold!").bold()}
- Want to split up a Setting into multiple variables/files? Just use
@SettingBuilder
.
structContentView:View{varbody:someView{SettingStack{SettingPage(title:"Settings"){ general misc}}}@SettingBuildervargeneral:someSetting{SettingPage(title:"General"){SettingText(title:"General Settings")}}@SettingBuildervarmisc:someSetting{SettingPage(title:"Misc"){SettingText(title:"Misc Settings")}}}
Need to store custom structs in
AppStorage
? Check out @IanKeen's awesomegist!You can pass in a custom
SettingViewModel
instance for finer control.
structPlaygroundView:View{@StateObjectvarsettingViewModel=SettingViewModel()varbody:someView{SettingStack(settingViewModel: settingViewModel){SettingPage(title:"Playground"){SettingGroup{SettingText(title:"Welcome to Setting!")}}} customNoResultsView:{VStack(spacing:20){Image(systemName:"xmark").font(.largeTitle)Text("No results for '\(settingViewModel.searchText)'")}.frame(maxWidth:.infinity, maxHeight:.infinity)}}} |
Author | Contributing | Need Help? |
---|---|---|
Setting is made byaheze. | All contributions are welcome. Justfork the repo, then make a pull request. | Open anissue or join theDiscord server. You can also ping me onTwitter. |
MIT LicenseCopyright (c) 2023 A. ZhengPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.
About
Compose beautiful preference panels.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.