4

I have a UITableView that has a list of UITableViewCells with custom corner radiuses. When swiping to edit, e.i. delete/insert, the corner radius is reset back to 0.

Image of cell's corner radius being reset

I've tried to set the corner radius while editing:

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

I've also tried implementing willBeginEditingRowAt in a similar way to try to get the corner radius to stay set. The last thing I tried was creating a custom UIContextualAction in trailingSwipeActionsConfigurationForRowAt, but it doesn't change anything.

There was a similar question asked about four years ago, but no conclusive solution was ever found. Any help or insight is appreciated!

Adeel Miraj
  • 2,472
  • 3
  • 22
  • 32
Jordan C.
  • 43
  • 1
  • 7

1 Answers1

8

You need to set corner radius and border to contentView.

cell.contentView.layer.cornerRadius = 13

Add this code to awakeFromNib or layoutSubviews method of UITableViewCell class.

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
}

I hope this will help you.

Komal Goyani
  • 779
  • 6
  • 25