2

I'm facing an issue with customizing the selected row's text color in a Table() in SwiftUI. I've set the foregroundColor to a custom color to match my app's design. However, when I select a row, the selected row's text becomes difficult to read.

If I delete the .foregroundColor(ApplicationColor.body), the color of selected row's text will become white automatically instead of the black (default).

(1) if I change the foregroundColor

Table(userState.regions, selection: $selectedRegion) {
    TableColumn("Region") { region in
        NavigationLink(value: region) {
            Text(region.name)
            .bold()
        }
    }
    TableColumn("Region", value: \.isoCode)
}
.foregroundColor(ApplicationColor.body)

(2) if I don't change the foregroundColor

Table(userState.regions, selection: $selectedRegion) {
    TableColumn("Region") { region in
        NavigationLink(value: region) {
            Text(region.name)
            .bold()
        }
    }
    TableColumn("Region", value: \.isoCode)
}

my environment:
macOS - 13.2.1 (22D68)
XCode - Version 14.2 (14C18)
build - My Mac --> macOS (13.2.1 (22D68) \

I have searched on the apple's document. there is no clue.

Yiran Feng
  • 21
  • 1

0 Answers0