Style a List

I want to give my list some styling (selection color, seperators, etc.) like I could with UITableView, however I can't seem to figure out how to do it.

I saw that there is a protocol `ListStyle`, but there is no documentation for it either in Xcode or online. Is this how we style lists, or is there something else that I'm missing?

Replies

Great question. I have been trying to hide the separators for 2 days now but no luck.
I am looking forward to someone answering this question. 🙂

I've been trying to wrap my head around how I should think about SwiftUI today for creating apps. Mostly - I'm not sure how far I should use it, and I don't know that because I'm not sure where SwiftUI should end and the platforms specific APIs should begin.


This quesiton is a perfect example.


Say I use the List struct on iOS, which basically becomes a table view (not sure what it renders down to specifically - maybe it's not a table view at all). Then, say I want to modify things specific to what make table view great like the leading/trailing contextual actions, selected background views or something similar - what does that look like?


Is SwiftUI meant to even support this?

I believe .listStyle() currently takes a value of .default, .plain, or .grouped.


I am also trying to find a way to hide the divider lines. I suppose I can use an HStack with a ForEach, but I am not sure of the performance implications of that with a long list. List seems like the right tool for the job, but we currently don't seem to have access to the right knobs to actually customize it. Hopefully that will change in the next couple of betas...

Did you ever figure this out?

From Session 216 SwiftUI Essentials:


A List add its ownPrimitive Views (Like the Divider between different rows)


Just our List, ForEach takes a Collection of Data an a View Builder that map each Data Item in is own View, but unlike List ForEach doesn't add any Visual Effect on its own, so if you use ForEach you must provide a Divider if you want it.


Divider()