Help support my open source work!
List finally supports setting list row separator color and style as of iOS15! They still don't support list inset because....reasons? Here is a quick tutorial of how to use the new functionality in iOS15 and if you need custom insets you can always hide the lines and then use a custom Divider on each cell. Now this hack of repo can die the slow painful death it deserves. https://www.hackingwithswift.com/quick-start/swiftui/how-to-adjust-list-row-separator-visibility-and-color
So while this project seems to work fairly well for many implementations it is clear that depending on specific setups sometimes the underlying UIKit code backing the SwiftUI list changes and ends up breaking this workaround. If it is not working my current suggestion would be to log an issue with specifics and instead do something along the lines of:
if #available(iOS 14, *) {
LazyVStack { content() }
} else {
List { content() }
}
func content() -> some View {
//Table rows go here
}
View extension to hide/modify List separators in SwiftUI iOS13 and iOS14.
SwiftUI List lacks the customizations necessary to hide/modify row separator lines. There are known workarounds with setting appearance for UITableView but many times this sets it for all UITableViews in the app and this workaround has also stopped working in iOS14. This project allows full customization of the separators on List and has been tested and works in both iOS13 and iOS14 when compiled with either Xcode 11 or Xcode 12.
List+Separator.swift
in your project. https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app
Show the standard single divider line (Note: this is equivalent to the sytem default so omitting is the same thing)
List { <content> }
.listSeparatorStyle(.singleLine)
Hide separators on the List
List { <content> }
.listSeparatorStyle(.none)
Show a single divider line with configurable color and insets
List { <content> }
.listSeparatorStyle(.singleLine, color: .red, inset: EdgeInsets(top: 0, leading: 50, bottom: 0, trailing: 20)
Show a single divider line and hide the separator on empty rows in the footer
List { <content> }
.listSeparatorStyle(.singleLine, hideOnEmptyRows: true)
We would love you for the contribution to SwiftUIListSeparator, check the LICENSE
file for more info.
Michael Schmidt – @FindMyClass – KineticSparks@gmail.com
Distributed under the MIT license. See LICENSE
for more information.