Set height of delete button that appears on swipe in UITableViewCell

enter image description hereI have UITableViewCell as shown in figure below.

The cell occupy the height occupied by delete. The cell height is set so as to keep spacing between two cell.

  • How can I recycle UITableViewCell objects created from a XIB?
  • Selecting a cell and changing the alpha of all cells in tableView - Swift
  • Candidate has non-matching type UITableView?
  • UISearchController searchBar in tableHeaderView animating out of the screen
  • How to implement table sections with core data
  • dynamic uitableview cell height
  • Now, when i swipe and delete button appears (red in color), it occupies cell height as given in picture above. I simply want to set its height to height of white part only or say the height of gray button. Can anyone help me on how to set the height of delete button that appears after swipe in UITableViewCell?

    5 Solutions Collect From Internet About “Set height of delete button that appears on swipe in UITableViewCell”

    The best way to solve this was overriding

    -(void)layoutSubviews in YourCustomCell:UITableViewCell    
    

    then

    if ([NSStringFromClass([subview class])isEqualToString:@"UITableViewCellDeleteConfirmationControl"]){
                UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
                                    CGRect buttonFrame = deleteButtonView.frame;
                                    buttonFrame.origin.x = Xvalue;
                                    buttonFrame.origin.y = Yvalue;
                                    buttonFrame.size.width = Width;
                                    buttonFrame.size.height = Height;
                                    deleteButtonView.frame = buttonFrame;
    
             }
    

    Use this code in your custom Cell class

     -(void) layoutSubviews
    {
        NSMutableArray *subviews = [self.subviews mutableCopy];
        UIView *subV = subviews[0];
        if ([NSStringFromClass([subV class])isEqualToString:@"UITableViewCellDeleteConfirmationView"]){
          [subviews removeObjectAtIndex:0];
          CGRect f = subV.frame;
          f.size.height = 106; // Here you set height of Delete button
          subV.frame = f;
         }
    

    }

    Add this method to your customCell.m file.

    -(void) layoutSubviews
    {
        NSMutableArray *subviews = [self.subviews mutableCopy];
        UIView *subview = subviews[0];
    
        if ([NSStringFromClass([subview class])isEqualToString:@"UITableViewCellDeleteConfirmationView"]){
            UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
            CGRect buttonFrame = 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 = 46;
            deleteButtonView.frame = buttonFrame;
            subview.frame=CGRectMake(subview.frame.origin.x, subview.frame.origin.y, subview.frame.size.width, 46);
            deleteButtonView.clipsToBounds=YES;
            subview.clipsToBounds=YES;
        }
    }
    

    Write below code in your custom cell hope it will work for you-

    - (void)willTransitionToState:(UITableViewCellStateMask)state
    {
        [super willTransitionToState:state];
        if(state == UITableViewCellStateShowingDeleteConfirmationMask)
         {
            [self performSelector:@selector(resetDeleteButtonSize) withObject:nil afterDelay:0];
         }
     }
    
    
    
    - (void)resetDeleteButtonSize
    {
        NSMutableArray *subviews = [self.subviews mutableCopy];
        while (subviews.count > 0)
        {
            UIView *subV = subviews[0];
            [subviews removeObjectAtIndex:0];
            if ([NSStringFromClass([subV class])isEqualToString:@"UITableViewCellDeleteConfirmationButton"])
            {
                CGRect f = subV.frame;
                f.size.height = 74;
                subV.frame = f;
                break;
            }
            else
            {
                [subviews addObjectsFromArray:subV.subviews];
            }
        }
    }
    

    SWIFT

    override func layoutSubviews() {
        super.layoutSubviews()
        for subview in self.subviews {
            if String(describing: type(of: subview.self)) == "UITableViewCellDeleteConfirmationView" {
                let deleteButton = subview
                let deleteButtonFrame = deleteButton.frame
                let newFrame = CGRect(x: deleteButtonFrame.minX, 
                                      y: deleteButtonFrame.minY,
                                      width: deleteButtonFrame.width,
                                      height: yourHeight)
                deleteButton.frame = newFrame
            }
        }
    }