UITableViewCell 编辑时重置圆角半径

问题描述 投票:0回答:1

我有一个 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,但它不会改变任何内容。

大约四年前有人提出过“类似的问题”,但从未找到最终的解决方案。任何帮助或见解表示赞赏!

ios swift xcode uitableview cornerradius
1个回答
8
投票
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 }

希望这对您有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.