ios - 如何清除 SwiftUI 中列表项上默认突出显示的灰色?

标签 ios swift uikit swiftui swiftui-list

我无法更改 List 的突出显示颜色item,在 UIKit 中 ID 很容易改变 TableViewCellSelection属性元素默认为无。对于如此简单的交互,我找不到解决方案,是不是我遗漏了什么?

谢谢你。

编辑:我试过这个,但没有奏效。

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

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

}

enter image description here

最佳答案

将代码添加到 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/

相关文章:

ios - 在 UIView 框架内绘制圆圈

ios - 无法将类型 '()' 的值转换为预期参数 '() -> void'

iphone - 为什么 -animateWithDuration :delay:options:animations:completion: blocking the UI?

ios - 使用drawRect延迟加载UIViews : drawing

ios - UIButton 文本内容每隔一秒更新一次

ios - SWIFT:快速点击 UIButton 会导致选票计数不正确

objective-c - NSXMLParser不解析最后一个节点(可能的内存问题)

ios - 如何使用 JSONModel 创建模型类?

arrays - 如何在可选中声明 [Int]

objective-c - Mac 应用程序下载、验证(通过 md5)并运行另一个大型应用程序?