Skip to main content

How to adjust List row separator visibility and color

About 2 minSwiftSwiftUIArticle(s)bloghackingwithswift.comcrashcourseswiftswiftuixcodeappstore

How to adjust List row separator visibility and color 관련

SwiftUI by Example

Back to Home

How to adjust List row separator visibility and color | SwiftUI by Example

How to adjust List row separator visibility and color

Updated for Xcode 15

New in iOS 15

SwiftUI provides two modifiers to control the way row separators look with its Lists, specifically listRowSeparator() for controlling whether separators are visible or not, and listRowSeparatorTint() for controlling the separator color.

For example, if you wanted to hide the separators for all rows in your list you could write this:

List {
    ForEach(1..<100) { index in
        Text("Row \(index)")
            .listRowSeparator(.hidden)
    }
}

Download this as an Xcode projectopen in new window

A list with no visible separators between rows.
A list with no visible separators between rows.

To adjust the color of the separator, use listRowSeparatorTint() like this:

List {
    ForEach(1..<100) { index in
        Text("Row \(index)")
            .listRowSeparatorTint(.red)
    }
}

Download this as an Xcode projectopen in new window

A list with thin red lines separating the rows.
A list with thin red lines separating the rows.

Again, you can attach that to individual list rows if you want more control.

::: detail Similar solutions…

How to adjust List row separator insets | SwiftUI by Example

How to adjust List row separator insets
SwiftUI tips and tricks | SwiftUI by Example

SwiftUI tips and tricks
All SwiftUI property wrappers explained and compared | SwiftUI by Example

All SwiftUI property wrappers explained and compared
Composing views to create a list row | SwiftUI by Example

Composing views to create a list row
Building a menu using List | SwiftUI by Example

Building a menu using List

:::


이찬희 (MarkiiimarK)
Never Stop Learning.