Swift and SwiftUI tutorials for Swift Developers

How to hide the SwiftUI List Row separators

To hide separators in SwiftUI we will use the modifier listRowSeparator and set its value to .hidden. Here you can see an example:

List {
            
            ForEach(restaurants.indices, id: \.self) { index in
                
                if(0...1).contains(index) {
                    
                    FullImageRow(restaurant: restaurants[index])
                }else{
                    
                    BasicImageRow(restaurant: restaurants[index])
                    
                }
                
            }
            
            .listRowSeparator(.hidden)
            
        }
        .listStyle(.plain)

In XCode the result is as follows:

If you want more precise control over the line separators, you can use an alternative version of .listRowSeparator by specifying the edges parameter. For example, if you want to keep the separator only at the top of the list view, you can write the code like this:

.listRowSeparator(.hidden, edges: .bottom)
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Article

How to change List Row separator color in SwiftUI

Next Article

How to change the background color in a List view in SwiftUI

Related Posts