Set height of delete button that appears on swipe in UITableViewCell

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

\"enterI have UITableViewCell as shown in figure below.

The cell occupy the h

相关标签:
5条回答
  • 2021-02-10 18:28

    For IOS 13 , the Position has been yet again change , not inside table view it is once again in _UITableViewCellSwipeContainerView . Thus you should iterate through that as well.Take a look below

    ([NSStringFromClass([subview class]) 
     isEqualToString:@"_UITableViewCellSwipeContainerView"]){
    
            for (UIView *deleteButtonSubview in subview.subviews){
    
                if ([NSStringFromClass([deleteButtonSubview class])
                     isEqualToString:@"UISwipeActionPullView"]) {
    
    
    
                    if ([NSStringFromClass([deleteButtonSubview.subviews[0] class]) isEqualToString:@"UISwipeActionStandardButton"]) {
    
                       //do what you want
                    }
                }
    
            }
        }
    
    0 讨论(0)
  • 2021-02-10 18:29

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

    }

    0 讨论(0)
  • 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
          }
        }
      }
    
    0 讨论(0)
  • 2021-02-10 18:47

    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;
    
             }
    
    0 讨论(0)
  • 2021-02-10 18:49

    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;
        }
    }
    
    0 讨论(0)
提交回复
热议问题