当我有一个UITableView
呈现的自定义类DrawerTableCell
的细胞,即宣告这样的UITableViewCell隐藏电池隔膜:UITableView的自定义selectedBackgroundView定制选择
class DrawerTableCell: UITableViewCell {
@IBInspectable var selectionColor: UIColor = .gray {
didSet {
configureSelectedBackgroundView()
}
}
func configureSelectedBackgroundView() {
let view = UIView()
view.backgroundColor = selectionColor
selectedBackgroundView = view
}
}
这UITableViewCell
子类是为了创建能够为单元格指定选定的背景颜色。
在我的视图控制器我设置:
tableView.separatorColor = .white
,我将单元配置是这样的:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "drawerCell") as! DrawerTableCell
cell.selectionColor = UIColor.blue
return cell
}
的结果是,当没有选定单元格,所有的隔板正确显示。当我选择一个单元格时,会显示背景颜色,但分隔符仅隐藏在所选单元格中。
有关如何将分隔线保留在选定单元格中的任何想法?
谢谢。