美文网首页
SwiftUI——给List添加Header和Footer

SwiftUI——给List添加Header和Footer

作者: 程序媛的程 | 来源:发表于2022-03-25 16:44 被阅读0次

    原文:https://www.ioscreator.com/tutorials/swiftui-header-footer-list-tutorial

    struct ContentView: View {
        // 1.
        let europeanCars = ["Audi","Renault","Ferrari"]
        let asianCars = ["Honda","Nissan","Suzuki"]
        
        var body: some View {
            NavigationView {
                List {
                    // 2.
                    Section(header:
                        Text("European Cars")) {
                            ForEach(0 ..< europeanCars.count) {
                                Text(self.europeanCars[$0])
                            }
                        }
                    // 3.
                    Section(header:
                        HStack {
                            Image(systemName: "car")
                            Text("Asian Cars")
                        }
                    // 4.
                    , footer: Text("This is a example list of a few car brands").font(.footnote))  {
                                   ForEach(0 ..< asianCars.count) {
                                       Text(self.asianCars[$0])
                                   }
                               }
                
                } .navigationBarTitle("Cars")
            }
               
        }
    }
    

    相关文章

      网友评论

          本文标题:SwiftUI——给List添加Header和Footer

          本文链接:https://www.haomeiwen.com/subject/rhddjrtx.html