< How to add sections to a list | How to set the background color of list rows using listRowBackground() > |
Updated for Xcode 12.0
SwiftUI’s list supports grouped or plain styles, just like UITableView
. The default is plain style, but if you want to change to grouped you should use the .listStyle(GroupedListStyle())
modifier on your list.
For example, this defines an example row and places it inside a grouped list:
struct ExampleRow: View {
var body: some View {
Text("Example Row")
}
}
struct ContentView: View {
var body: some View {
List {
Section(header: Text("Examples")) {
ExampleRow()
ExampleRow()
ExampleRow()
}
}.listStyle(GroupedListStyle())
}
}
SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.