📜  swiftui foreach - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:02.454000             🧑  作者: Mango

代码示例2
struct ContentView: View {
    let colors: [Color] = [.red, .green, .blue]

    var body: some View {
        VStack {
            ForEach(colors, id: \.self) { color in
                Text(color.description.capitalized)
                    .padding()
                    .background(color)
            }
        }
    }
}