2

I can't change the highlighted color of the List item, in UIKit Id change easily TableViewCell's Selection property element Default to None. I can't find a solution for such a simple interaction, is there something that I missing?

Thank you.

Edit: I tried this but not worked.

NavigationLink(destination: DetailView(detail: self.viewModel.characters.results[index])) {  

CharacterCell(character: self.viewModel.characters.results[index])
                                    .buttonStyle(PlainButtonStyle())

}

enter image description here

GreatCornholio
  • 97
  • 2
  • 16

1 Answers1

0

Add the code to a init()

   init() {
        // Set selected (onTapped) background color of cell.
        let color = UIView()
        color.backgroundColor = UIColor.red
        UITableViewCell.appearance().selectedBackgroundView = color
    }

For example:

import SwiftUI

struct SomeView: View {

    init() {
        // Set selected (onTapped) background color of cell.
        let color = UIView()
        color.backgroundColor = UIColor.red
        UITableViewCell.appearance().selectedBackgroundView = color
    }

    var body: some View {

        // Your List/ForEach code
        Text(/"Hello, World!")
    }
}

I have noticed that swiftUI preview doesn't show the change, but inside the simulator or running on a device you will see the effect.

In your case, you would set the UIColor.clear and this should eliminate the gray as required.

James
  • 247
  • 2
  • 6