Home > database >  SwiftUI List on macOS: highlighting content in the selected row?
SwiftUI List on macOS: highlighting content in the selected row?

Time:11-08

In a SwiftUI List, when a row is selected, a blue selection is drawn in the selection, and foreground Text with the default primary color is automatically made white. For other views with custom colors, I'd like to be able to make sure they become tinted white to match the system apps. For example, see the blue dot on the selected row:

list

Example code:

List(selection: $selection) {
    ForEach(0..<4) { index in
        HStack {
            Image(systemName: "circle.fill")
                .foregroundColor(.blue)
            Text("Test")
        }
        .tag(index)
    }
}

Any tips on how to achieve the correct result here?

  • Related