我正在尝试设置UITableViewCell的焦点状态的颜色。问题是我注意到单元格周围有一个奇怪的白色边框,所以我将tableview背景设为黑色,并将焦点颜色设置为黑色,以检查是否确实如此,你可以在屏幕截图中看到,有一个细胞周围有微弱的白色/灰色边框。有谁知道怎么摆脱这个?
class MyCell: UITableViewCell {
override func awakeFromNib() {
backgroundView = nil
backgroundColor = UIColor.clear
}
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocus(in: context, with: coordinator)
if context.nextFocusedView === self {
coordinator.addCoordinatedAnimations({
self.contentView.backgroundColor = UIColor.black
}, completion: nil)
}
else {
coordinator.addCoordinatedAnimations({
self.contentView.backgroundColor = UIColor.clear
}, completion: nil)
}
}
答案 0 :(得分:0)
在
中尝试以下代码override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocus(in: context, with: coordinator)
if context.nextFocusedView === self {
coordinator.addCoordinatedAnimations({
self.contentView.backgroundColor = UIColor.black
self.contentView.layer.borderColor = UIColor.black
}, completion: nil)
}
else {
coordinator.addCoordinatedAnimations({
self.contentView.backgroundColor = UIColor.clear
self.contentView.layer.borderColor = UIColor.clear
}, completion: nil)
}
}