SwiftUI—使用section将列表分为几个组

简介: SwiftUI—使用section将列表分为几个组

当列表里的数据很多,并且这些数据可以被分组时,我们可以使用section,将列表分为几个组。


示例代码:


struct ContentView : View {
    private var languages = ["Swift", "Objective-C"]
    @State private var selectedLanguage = 0
    @State var workingYear: Double = 2
    @State var enableNotification = false
    var body: some View {
        NavigationView {
            Form {
                Section(header: Text("Please enter your information:"), footer: Text("Note: Enabling notification to get more infomration")) {
                    Picker(selection: $selectedLanguage, label: Text("Languages")) {
                       ForEach(0 ..< languages.count) {
                        Text(self.languages[$0]).tag($0)
                       }
                    }.pickerStyle(SegmentedPickerStyle())
                    HStack{
                        Text("Working years")
                        Slider(value: $workingYear, in: 1...10, step: 1)
                    }
                    Toggle(isOn: $enableNotification) {
                        Text("Enable Notification")
                    }
                }
                Button(action: {
                // activate theme!
                    print("Your programming language: \(self.languages[self.selectedLanguage])")
                    print("Your working years: \(Int(self.workingYear))")
                    print("Enable notification: \(self.enableNotification)")
                }) {
                    Text("Submit")
                }
            }.navigationBarTitle(Text("Profiles"))
        }
    }
}


2466108-c5714db96e17b65d.webp.jpg

目录
相关文章
|
5月前
|
前端开发 开发者 容器
SAP Fiori Elements List Report 应用里 Header 字段的绑定路径
SAP Fiori Elements List Report 应用里 Header 字段的绑定路径
40 0
|
JavaScript 前端开发
laravel-admin1.*获取Grid列表页选中的行
laravel-admin1.*获取Grid列表页选中的行
99 0
【mpvue】radio-group 标签组 点击两次 label才可以选中状态
1.问题复现 用 radio-group 标签组实现单选功能,点击两次才可以使 label 呈现选中状态,但是e.target.value 的值已经发生变化了。
235 0
SwiftUI—如何删除List列表里的记录
SwiftUI—如何删除List列表里的记录
307 0
SwiftUI—如何删除List列表里的记录
SwiftUI—使用TabView包含和切换多个页面
SwiftUI—使用TabView包含和切换多个页面
817 0
SwiftUI—使用TabView包含和切换多个页面
|
XML 前端开发 数据格式
SAP Fiori Elements 在本地测试模式下如何修改 List Report 里字段标签和图标
通过 Jerry 这篇文章 在没有任何前端开发经验的基础上, 创建第一个 SAP Fiori Elements 应用 介绍的步骤,创建一个简单的 SAP Fiori Elements 应用。
113 0
SAP Fiori Elements 在本地测试模式下如何修改 List Report 里字段标签和图标
如何找到Fiori Launchpad tile所属的catalog id
以Marketing Cloud的这个contact and profile的catalog为例:
如何找到Fiori Launchpad tile所属的catalog id
如何将SAP Document Builder的word控件设置成只读模式
如何将SAP Document Builder的word控件设置成只读模式
86 0
如何将SAP Document Builder的word控件设置成只读模式
|
C# 前端开发 数据安全/隐私保护
WPF QuickStart系列之附加属性(Attached Property)
原文:WPF QuickStart系列之附加属性(Attached Property) 这一篇博客是关于如何使用附加属性和创建自定义附加属性的。 1. 附加属性使用, WPF中对附加属性使用最多的莫过于对控件布局时设置控件的位置,例如在Canvas中有一个Rectangle, Ellipse, ...
973 0
|
C#
How do I duplicate a resource reference in code behind in WPF?如何在WPF后台代码中中复制引用的资源?
原文 https://stackoverflow.com/questions/28240528/how-do-i-duplicate-a-resource-reference-in-code-behind-in-wpf 如何在WPF后台代码中中复制引用的资源? In my application, I have a color resources.
800 0