How to customize the selected row's color in a Table in SwiftUI

I'm making a macOS app using SwiftUI. I have a Table view. I have selection enabled but I can't find any way to customize the selection color - it's always blue.

My table looks something like this:

		Table(of: MyObj.self, selection: $selectedID, sortOrder: $sortOrder) {
        TableColumn("Column Name") { obj in
            // do some custom view
        }
        . . .
    } rows: {
        Foreach (model.items) { obj in
            TableRow(obj)
        }
    }

If I change the AccentColor in Assets, that does the trick - though I guess it will change what is used elsewhere in the app (wherever an accent color is used).

I tried putting an .accentColor(.green) on the Table but that didn't do anything.

There may be something to do with AccentColor.

May be you could change it programmatically when the table is visible.

Some details here: https://www.reddit.com/r/SwiftUI/comments/10kcrr6/changing_the_value_of_the_default_accent_color/

Hope that helps.

Thanks @sha921 . It's unfortunate that apple doesn't let you modify this color through code. One oddity that I am having is that the colors (light and dark) that I set in Xcode for the accent color are not the colors displayed.

I set the accent color for light to #aec9f1, and for dark to #373c55. But when i run the app and select a row in my table, in light mode it is #95aed4, and in dark mode it is #1d2138 - totally not the colors I picked. I don't have any opacity set anywhere, so I can't figure out why the actual colors aren't what I specified. (If I don't have the AccentColor, I confirm that the selection goes back to the system blue).

Any suggestions on what to check?

How to customize the selected row's color in a Table in SwiftUI
 
 
Q