2017-04-06 57 views
1

我想设置UITableViewCell的焦点状态的颜色。问题是我注意到了单元格周围有一个奇怪的白色边框,所以我将tableview背景设置为黑色,并将焦点颜色设置为黑色,以检查是否确实如此,并且您可以在屏幕截图中看到,有一个细胞周围微弱的白色/灰色边框。有谁知道如何摆脱这个?设置UITableViewCell的焦点颜色

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

回答

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) 
    } 
} 
+0

下面的代码这并没有工作:(如果您看看第一个屏幕截图,你会看到灰色的焦点颜色,然后变成黑色,我认为这是事实突破。和“看起来”像一个边界。 – dubdub