簡體   English   中英

編輯時重置 UITableViewCell 的角半徑

[英]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類的awakeFromNiblayoutSubviews方法中。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM