Set height of delete button that appears on swipe in UITableViewCell

后端 未结 5 765
独厮守ぢ
独厮守ぢ 2021-02-10 18:25

\"enterI have UITableViewCell as shown in figure below.

The cell occupy the h

5条回答
  •  独厮守ぢ
    2021-02-10 18:47

    Swift 5, works for iOS12, iOS13 and iOS14

      func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
        // for iOS13, iOS14
        if let swipeContainerView = tableView.subviews.first(where: { String(describing: type(of: $0)) == "_UITableViewCellSwipeContainerView" }) {
          if let swipeActionPullView = swipeContainerView.subviews.first, String(describing: type(of: swipeActionPullView)) == "UISwipeActionPullView" {
            swipeActionPullView.frame.size.height -= 10
          }
        }
    
        // for iOS12
        tableView.subviews.forEach { subview in
          if String(describing: type(of: subview)) == "UISwipeActionPullView" {
            subview.frame.size.height -= 10
          }
        }
      }
    

提交回复
热议问题