How to remove the Last row separator in SwiftUI List
Table of Contents
The last separator or the bottom separator in SwiftUI List is actually a section separator.
Since iOS 15, you can easily remove a section separator by using the listSectionSeparator(_:edges:)
modifer.
You can easily support sarunw.com by checking out this sponsor.
Debug 10x faster with Proxyman: Your ultimate tool to capture HTTPs requests/ responses, natively built for your iPhone and macOS. Special deal for Black Friday: Get 30% off for all Proxyman licenses with code “BLACKFRIDAY2024”.
How to remove the Last row separator in SwiftUI List
The listSectionSeparator(_:edges:)
control the visibility of section separators.
To hide the section separator, we pass Visibility.hidden
for the first argument.
listSectionSeparator(_:edges:)
also accept an optional second argument that specifies the edges that you want to hide.
Each Section
view can have two separators, top and bottom, wrapping the rows in that section. The last separator is referred to as a bottom edge of a section separator. So, we pass VerticalEdge.bottom
as the second argument.
To hide it, we apply .listSectionSeparator(.hidden, edges: .bottom)
to Section
.
NavigationView {
List {
Section("Section Header") {
ForEach(0..<7) { i in
Text("Row \(i.description)")
}
}
.listSectionSeparator(.hidden, edges: .bottom)
}
.listStyle(.plain)
.navigationTitle("List")
}
Read more article about SwiftUI, List, iOS 15, or see all available topic
Enjoy the read?
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.
Become a patron Buy me a coffee Tweet ShareWhat is Swift Computed Property
There are two kinds of properties in Swift, Stored, and computed. Let's learn the difference.
How to organize Flutter import directives in VSCode
Learn how to Remove unused imports and Sort import packages by their name.