2

I have custom table cell. Each cell have different height. I want to give swipe delete button with cell height.

I have attached screen shot for

I have used view in cell. View height is cell height - 16. Top-bottom margin 8.

So please help me to do this.

Janki Gadhiya
  • 4,492
  • 2
  • 29
  • 59
Kush Thakkar
  • 59
  • 1
  • 1
  • 7

1 Answers1

0

Use this code in your Custom Cell Swift class

override func layoutSubviews() {
    let fltHeight:CGFloat = 46
    var subviews: [Any] = self.subviews
    let subview: UIView? = subviews[0] as? UIView
    if NSClassFromString("UITableViewCellDeleteConfirmationView") != nil {
        if (subview?.isKind(of: NSClassFromString("UITableViewCellDeleteConfirmationView")!))! {
            let deleteButtonView: UIView? = (subview?.subviews[0])
            var buttonFrame: CGRect? = deleteButtonView?.frame
            buttonFrame?.origin.x = (deleteButtonView?.frame.origin.x)!
            buttonFrame?.origin.y = (deleteButtonView?.frame.origin.y)!
            buttonFrame?.size.width = (deleteButtonView?.frame.size.width)!
            buttonFrame?.size.height = fltHeight
            deleteButtonView?.frame = buttonFrame!

            // Placing at the center of the cell.
            subview?.frame = CGRect(x: CGFloat((subview?.frame.origin.x)!),
                                    y: CGFloat((subview?.frame.origin.y)! + ((subview?.frame.size.height)!-fltHeight)/2),
                                    width: CGFloat((subview?.frame.size.width)!),
                                    height: CGFloat(fltHeight))
            deleteButtonView?.clipsToBounds = true
            subview?.clipsToBounds = true
        }
    }
}
yashica15
  • 53
  • 13