ios - 编辑时 UITableViewCell 的角半径被重置
问题描述
我有一个 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
}
我希望这能帮到您。
推荐阅读
- arrays - Swift:如何向 JSON 数组添加多个项目?
- c++ - C++ 显示向量
- three.js - 用三角形绘制四面体
- python - 在 Windows 10 命令提示符中运行 python (3.8.2) 文件时出错
- azure-media-services - 如何确保直播结束后停止直播?
- java - 具有类实例的 Setter 这可能吗?
- android - 更改传递的参数时,Flutter setstate 不会再次调用 build
- matlab - 寻找一个好的 MatLab 函数
- r - R DataTable 解决方案快速重塑
- flutter - 为每个项目构建一个复选框方法