gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:14:43 25 4
gpt4 key购买 nike

我无法更改 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com