Jor*_* C. 3 xcode cornerradius uitableview ios swift
我有一个 UITableView,它有一个带有自定义圆角半径的 UITableViewCells 列表。滑动编辑时,ei 删除/插入,圆角半径重置为 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))
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过以类似的方式实现 willBeginEditingRowAt 以尝试使拐角半径保持不变。我尝试的最后一件事是在 trailingSwipeActionsConfigurationForRowAt 中创建自定义 UIContextualAction,但它不会改变任何东西。
您需要将角半径和边框设置为contentView。
cell.contentView.layer.cornerRadius = 13
Run Code Online (Sandbox Code Playgroud)
将此代码添加到类的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
}
Run Code Online (Sandbox Code Playgroud)
我希望这能帮到您。