[英]Corner Radius of UITableViewCell Being Reset when Editing
我有一個 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))
}
}
我也嘗試過以類似的方式實現 willBeginEditingRowAt 以嘗試使拐角半徑保持不變。 我嘗試的最后一件事是在 trailingSwipeActionsConfigurationForRowAt 中創建自定義 UIContextualAction,但它不會改變任何東西。
您需要將角半徑和邊框設置為contentView
。
cell.contentView.layer.cornerRadius = 13
將此代碼添加到UITableViewCell
類的awakeFromNib
或layoutSubviews
方法中。
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
}
我希望這能幫到您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.