设置UITableViewCell的焦点颜色

时间:2017-04-06 18:01:55

标签: ios swift uitableview tvos collectionview

我正在尝试设置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)
    }
}

在滚动期间在单元格之间转换时 enter image description here

非常微弱的线条勾勒出细胞 Very faint line outlining the cell

1 个答案:

答案 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)
    }
}