ios – How Can I Change The Background Color of A List View Row Element’s Press State in SwiftUI?


So I know how to change the background color of a list row element in swiftUI using .listRowBackground(Color.red) for example. But when I do this the row no longer changes color when you press it. Note I do not mean the active row… I mean when your finger is pressing down on the row I want it to change color as visual feedback. Any suggestions on how I can retain the press state background color? Or even better how can I customize that press color?

Here’s the code I’m playing with:

List {
     ForEach((viewModel.bookmarks )!, id: \.id) { bookmark in
         Button(action: {onTap(bookmark)}, label: {
                            BookmarkCell(label: bookmark.trackName,
                                         createAt: bookmark.date.bookmarkFormat(),
                                         savePosition: bookmark.position.format(formatType: FormatType.hhmmss),
                                         note: bookmark.note)
                        }).listRowBackground(Color.red) // for testing
    }
}

Any suggestions would be greatly appreciated.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img