UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Customizing the look of hierarchical/embedded/expanding lists

Forums > SwiftUI

With regards to hierarchical lists, is there a way to customize the background colors, chevron colors, etc.? I know how to do them within a NavigationView and other Lists (e.g., this), but I can't get the customization to work in an expanding list.


I once styled it in clearing the background and using my own gradient with a ZStack. But you have to rely on

UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().backgroundColor = .clear

With these you can set your own background color as well.

You can use it in the init() of your View.


Thanks for that, @Hatsushira! If I'm using it correctly, like this:

struct ExpandableFolder: Hashable {
    let label: String
    var contents: [ExpandableFolder]?

struct ContentView: View {
    init() {
        UITableView.appearance().backgroundColor = UIColor.clear
        UITableViewCell.appearance().backgroundColor = UIColor.clear

    let folders: [ExpandableFolder] = [
        ExpandableFolder(label: "Category A",
                         contents: [ExpandableFolder(label: "Subgroup A.1"), ExpandableFolder(label: "Subgroup A.2")]),

        ExpandableFolder(label: "Category B",
                         contents: [ExpandableFolder(label: "Subgroup B.1",
                                                     contents: [ExpandableFolder(label: "Sub-Subgroup B.1.1")])]),

    var body: some View {
        List(folders, id: \.self, children: \.contents) { row in

this affects what's behind the list of Text rows. However, I'm looking to change the appearance of the rows themselves. More specifically, the color of the chevron symbols at far right; I'm trying to make them a different color than Color.accentcolor.


The List itself you can style with listRowBackground and listItemTint. I don't know how this affects the chevron color, though. In my experience it doesn't...


Hmmm. I haven't been able to get either of those to work with the embedded lists; I've tried placing the code inside the List{} view as well as trying them as modifiers to the view, but the list's appearance never changes. Actually, the only code that's cause any visual difference is setting UITableView.appearance().backgroundColor equal to a visible Color (e.g., .red, .blue, etc.).


Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.