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.

2      

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.

2      

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
            Text(row.label)
        }
    }
}

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.

2      

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...

2      

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.).

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out 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.