我有一个 UITableView,其中包含带有自定义角半径的 UITableViewCells 列表。滑动进行编辑时,例如删除/插入,圆角半径重置回0。
我尝试在编辑时设置圆角半径:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) as? HabitTableViewCell else { return }
cell.layer.cornerRadius = 13
if editingStyle == .delete {
controller.delete(habit: frc.object(at: indexPath))
}
}
我还尝试以类似的方式实现 willBeginEditingRowAt 来尝试让角半径保持设置。我尝试的最后一件事是在 TrailingSwipeActionsConfigurationForRowAt 中创建自定义 UIContextualAction,但它不会改变任何内容。
contentView
。
cell.contentView.layer.cornerRadius = 13
将此代码添加到
awakeFromNib
或
layoutSubviews
类的 UITableViewCell
方法中。override func awakeFromNib() {
super.awakeFromNib()
self.contentView.layer.cornerRadius = 13
// Your border code here (set border to contentView)
self.contentView.layer.borderColor = UIColor.blue.cgColor
self.contentView.layer.borderWidth = 3
}
希望这对您有帮助。