### Swift Package Manager Installation Source: https://github.com/aheze/setting/blob/main/README.md Installs the Setting library using Swift Package Manager. Requires iOS 15+ or macOS Monterey. ```shell https://github.com/aheze/Setting ``` -------------------------------- ### SettingPage Navigation Example Source: https://github.com/aheze/setting/blob/main/README.md Shows how to create multiple SettingPage elements within a SettingGroup to provide navigation to different sub-sections of the settings. Each SettingPage can have its own content and can be customized with a preview icon. ```swift 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") } } } ``` -------------------------------- ### Basic SettingText Example Source: https://github.com/aheze/setting/blob/main/README.md Demonstrates the basic usage of SettingText to display a simple label within a SettingGroup. This is a foundational element for creating settings screens. ```swift struct PlaygroundView: View { var body: some View { SettingStack { SettingPage(title: "Playground") { SettingGroup { SettingText(title: "Hello!") } } } } } ``` -------------------------------- ### SettingPicker Example Source: https://github.com/aheze/setting/blob/main/README.md Demonstrates how to use SettingPicker to allow users to select an option from a list of choices. It supports customization of the display mode, such as using a menu for selection, and integrates with @AppStorage for data persistence. ```swift struct PlaygroundView: View { @AppStorage("index") var index = 0 var body: some View { 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 ) ) } } } } } ``` -------------------------------- ### SettingCustomView Example Source: https://github.com/aheze/setting/blob/main/README.md Shows how to embed any SwiftUI view within a Setting. This allows for highly customized UI elements within the settings screen, offering flexibility beyond the standard components. ```swift 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) } } } ``` -------------------------------- ### SettingToggle and SettingSlider Example Source: https://github.com/aheze/setting/blob/main/README.md Illustrates the use of SettingToggle for boolean states and SettingSlider for numerical input. Both utilize @AppStorage for persistent data storage, allowing UI elements to reflect and update stored values. ```swift struct PlaygroundView: View { @AppStorage("isOn") var isOn = true @AppStorage("value") var value = Double(5) var body: some View { SettingStack { SettingPage(title: "Playground") { SettingGroup { SettingToggle(title: "On", isOn: $isOn) } SettingGroup(header: "Slider") { SettingSlider( value: $value, range: 0 ... 10 ) } } } } } ``` -------------------------------- ### MIT License Source: https://github.com/aheze/setting/blob/main/README.md The MIT License text for the Setting library. ```text 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. ``` -------------------------------- ### Organizing Settings with @SettingBuilder Source: https://github.com/aheze/setting/blob/main/README.md Demonstrates using @SettingBuilder to organize settings across multiple variables or files, making complex setting structures more manageable. It shows how to create distinct setting sections like 'general' and 'misc'. ```swift struct ContentView: View { var body: some View { SettingStack { SettingPage(title: "Settings") { general misc } } } @SettingBuilder var general: some Setting { SettingPage(title: "General") { SettingText(title: "General Settings") } } @SettingBuilder var misc: some Setting { SettingPage(title: "Misc") { SettingText(title: "Misc Settings") } } } ``` -------------------------------- ### SwiftUI Preference Panel Creation with Setting Source: https://github.com/aheze/setting/blob/main/README.md Demonstrates how to create a preference panel using the Setting library in SwiftUI. It shows how to use SettingStack, SettingPage, SettingGroup, SettingToggle, SettingCustomView, and SettingText for building UI elements and managing state with AppStorage. ```swift 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!") } } } } } } ``` -------------------------------- ### Using SettingViewModel for Custom Control Source: https://github.com/aheze/setting/blob/main/README.md Shows how to instantiate and use a custom SettingViewModel with SettingStack for advanced control, including displaying a custom view when no search results are found. It highlights the integration of view models for managing setting states and behaviors. ```swift struct PlaygroundView: View { @StateObject var settingViewModel = SettingViewModel() var body: some View { 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) } } } ``` -------------------------------- ### Basic SettingText Usage Source: https://github.com/aheze/setting/blob/main/README.md Demonstrates the basic usage of SettingText components with unique IDs and titles. These are fundamental building blocks for displaying text-based settings. ```swift SettingText(id: "Announcement 1", title: "Hello!") SettingText(id: "Announcement 2", title: "Hello!") ``` -------------------------------- ### Custom Styling with SettingCustomView Source: https://github.com/aheze/setting/blob/main/README.md Illustrates how to wrap Setting components within SettingCustomView to apply custom styling, such as making text bold. This enables fine-grained control over the appearance of settings. ```swift SettingCustomView { SettingText(title: "I'm bold!") .bold() } ``` -------------------------------- ### Conditional SettingToggle and SettingText Source: https://github.com/aheze/setting/blob/main/README.md Shows how to use SettingToggle with state binding and implement conditional rendering of SettingText based on the toggle's state. This allows for dynamic UI updates. ```swift SettingToggle(title: "Turn on", isOn: $isOn) if isOn { SettingText("I'm turned on!") } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.