SwiftUI中如何给List添加Header和Footer

7个月前 363次点击 来自 iOS

标签: SwiftUI

原文链接:
SwiftUI Header and 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")
        }
           
    }
}
Card image cap
开发者雷

尘世间一个小小的开发者,每天增加一些无聊的知识,就不会无聊了

要加油~~~

技术文档 >> 系列应用 >>
热推应用
Let'sLearnSwift
学习Swift的入门教程
PyPie
Python is as good as Pie
标签