當我有一個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
}
的結果是,當沒有選定單元格,所有的隔板正確顯示。當我選擇一個單元格時,會顯示背景顏色,但分隔符僅隱藏在所選單元格中。
有關如何將分隔線保留在選定單元格中的任何想法?
謝謝。