我无法更改 List
的突出显示颜色item,在 UIKit 中 ID 很容易改变 TableViewCell
的 Selection
属性元素默认为无。对于如此简单的交互,我找不到解决方案,是不是我遗漏了什么?
谢谢你。
编辑:我试过这个,但没有奏效。
NavigationLink(destination: DetailView(detail: self.viewModel.characters.results[index])) {
CharacterCell(character: self.viewModel.characters.results[index])
.buttonStyle(PlainButtonStyle())
}
最佳答案
将代码添加到 init()
init() {
// Set selected (onTapped) background color of cell.
let color = UIView()
color.backgroundColor = UIColor.red
UITableViewCell.appearance().selectedBackgroundView = color
}
例如:
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!")
}
}
我注意到 swiftUI 预览没有显示更改,但是在模拟器内或在设备上运行时,您会看到效果。
在您的情况下,您将设置 UIColor.clear 并且这应该根据需要消除灰色。
关于ios - 如何清除 SwiftUI 中列表项上默认突出显示的灰色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60951530/