TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: What is the best way to change the height/wide of the separator in a List?

Forums > SwiftUI

I want to change the height of the separator to make it more noticeable. The best solution I found out was one called Custom Separator/Divider in SwiftUI Lists from SwiftUI Recipes (which I can't link in this forum), but the separator padding is too big. For example, if this is my code:

struct ThreadsList: View {
    var body: some View {
        List {
            ForEach(1 ... 10, id: \.self) { i in
                TextThreadRow()
                    .listRowSeparator(.hidden)
            }
            .separator(showLast: false) { _ in
                Rectangle()
                    .fill(Color.threadListSeperator)
                    .listRowInsets(EdgeInsets())
            }
        }
        .listStyle(GroupedListStyle())
    }
}

I get this: A very wide separator

If I limit the separator's frame height like this:

struct ThreadsList: View {
    var body: some View {
        List {
            ForEach(1 ... 10, id: \.self) { i in
                TextThreadRow()
                    .listRowSeparator(.hidden)
            }
            .separator(showLast: false) { _ in
                Rectangle()
                    .fill(Color.threadListSeperator)
                    .frame(height: 5)
                    .listRowInsets(EdgeInsets())
            }
        }
        .listStyle(GroupedListStyle())
    }
}

I get this: A properly wide separator but with a huge margin

Is there any other way to achieve this?

2      

My solution was to use this answer from StackOverflow to make the seperator.

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.