设置在UITableViewCell中刷卡时出现的删除button的高度

在这里输入图像说明 我有如下图所示的UITableViewCell

小区占用删除的高度。 单元高度设置为保持两个单元之间的间距。

现在,当我滑动和删除button出现(红色),它占据上图中给出的单元格高度。 我只是想将其高度设置为白色部分的高度,或者说是灰色button的高度。 任何人都可以帮助我如何设置在UITableViewCell刷卡后出现的删除button的高度?

解决这个问题的最好办法就是压倒一切

 -(void)layoutSubviews in YourCustomCell:UITableViewCell 

然后

 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; } 

在您的自定义Cell类中使用此代码

  -(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; } 

}

将此方法添加到您的customCell.m文件。

 -(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; } } 

在你的自定义单元格中写下面的代码,希望它能为你工作 –

 - (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]; } } } 

迅速

 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 } } }