UITableViewCell content overlaps delete button when in editing mode in iOS7

前端 未结 11 1051
长情又很酷
长情又很酷 2020-12-15 07:50

I am creating a UITableView with custom UITableViewCells. iOS 7\'s new delete button is causing some problems with the layout of my cell.

I

相关标签:
11条回答
  • 2020-12-15 08:12

    Just use this method in your custom TableViewCell class you can get the perfect answer,

    Here self is UITableviewCell

    - (void)layoutSubviews {
    
    [super layoutSubviews];
    
        for (UIView *subview in self.subviews) {
    
        for (UIView *subview2 in subview.subviews) {
    
            if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) { // move delete confirmation view
    
                [subview bringSubviewToFront:subview2];
    
            }
         }
      }
    }
    
    0 讨论(0)
  • 2020-12-15 08:12

    And if any one want to adjust the Delete Button Size, Use the following Code

    - (void)layoutSubviews {
    
        [super layoutSubviews];
    
        for (UIView *subview in self.subviews) {
    
            for (UIView *subview2 in subview.subviews) {
    
                if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) { // move delete confirmation view
    
                    CGRect rect = subview2.frame;
                    rect.size.height = 47; //adjusting the view height
                    subview2.frame = rect;
    
                    for (UIButton *btn in [subview2 subviews]) {
    
                        if ([NSStringFromClass([btn class]) isEqualToString:@"UITableViewCellDeleteConfirmationButton"]) { // adjusting the Button height
                            rect = btn.frame;
                            rect.size.height = CGRectGetHeight(subview2.frame);
                            btn.frame = rect;
    
                            break;
                        }
                    }
    
                    [subview bringSubviewToFront:subview2];
    
                }
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-15 08:15

    As tcurdt mentioned, you could switch to autolayout to solve this issue. But, if you (understandably) don't want to mess with autolayout just for this one instance, you can set the autoresizingMask and have that turned automatically into the appropriate autolayout constraints.

    label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    
    0 讨论(0)
  • 2020-12-15 08:22

    Best way to remove this problem is that add an image in cell and set it in Backside.

          UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgImg.png"]];
          imageView.frame = CGRectMake(0, 0, 320, yourCustomCell.frame.size.height);
          [yourCustomCell addSubview:imageView];
          [yourCustomCell sendSubviewToBack:imageView];
    

    If your text would overlap the delete button then implement Autolayout. It'll manage it in better way.

    One more case can be generate that is cellSelectionStyle would highlight with default color. You can set highlight color as follows

          yourCustomCell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    Set your table cell's selection style to UITableViewCellSelectionStyleNone. This will remove the blue background highlighting or other. Then, to make the text label or contentview highlighting work the way you want, use this method in yourCustomCell.m class.

    - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
    {
        if (highlighted)
            self.contentView.backgroundColor = [UIColor greenColor];
         else
            self.contentView.backgroundColor = [UIColor clearColor];
    }
    

    I hope you understand it in a better way.

    0 讨论(0)
  • 2020-12-15 08:23

    Try this: Might be you are setting cell setBackgroundImage in cellForRowAtIndexPath (Delegate Method). Do not set this here. Set your image in:

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellList.png"]]; }
    

    Enjoy Coding.

    0 讨论(0)
提交回复
热议问题