structContentView: View { var body: someView { Form { Section { // Version 1: String label & String value LabeledContent("Name", value: "Samantha Carter")
// Version 2: String label & formatted value LabeledContent("Age", value: 43, format: .number)
// Version 3: String label & any View as value LabeledContent("Home Planet") { Image(systemName: "globe.europe.africa.fill") Text("Earth") }
// Version 4: Any View as value & any View as a label LabeledContent { Text("SG-1") } label: { Text("Team") Text("SGC") } } } } }
另外,LabeledContent 还能这样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
structContentView: View { var body: someView { Form { // Version 4: Any View as value & any View as a label LabeledContent { Text("Value") } label: { Text("Label") Text("Second Label") Text("Third Label") Text("Fourth Label") // You can add more views, but styling won't change } } } }