UItableview Separator line's height

2019-09-18 06:00发布

问题:

Can I adjust the height of the UITableview's separator line? I add UIView at the cell to use as separator line and its good, the problem is that when I slide the cell to delete it, the delete button is the problem, its overlapping the separator line, or can I adjust the delete button's height?

回答1:

If you can't resize the delete button, resize your bottom UIView so it can overlap the delete button.



回答2:

The code pasted in by Rashad is pretty old (found here) and doesn't seem to work for iOS 7 or iOS 8.

Here is updated code that works:

-(void)layoutSubviews {

    UIView *deleteButtonView = nil;

    for (UIView *subview in self.subviews) {
        // find the delete view in iOS 8
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]){
            deleteButtonView = subview;
            break;
        }

        // find the delete view in iOS 7
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellScrollView"]) {
            for (UIView *secondSubview in [subview subviews]) {
                if ([NSStringFromClass([secondSubview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
                    deleteButtonView = secondSubview;
                    break;
                }
            }
        }
    }

    int heightOffset = 5;
    CGRect buttonFrame = deleteButtonView.frame;
    buttonFrame.origin.y = heightOffset;
    buttonFrame.size.height = self.frame.size.height-2*heightOffset;
    deleteButtonView.frame = buttonFrame;
}


回答3:

I always draw separator line like a subView on contentView of cell. And disable separatorStyle in tableView. And customise delete button like here: https://stackoverflow.com/a/22396248/887325



回答4:

In you TableViewCell layoutSubviews method write this:

if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
    UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
    CGRect newf = deleteButtonView.frame;
    newf.origin.x = 250;
    newf.origin.y = 47;
    newf.size.width = 30;
    newf.size.height = 50;

    deleteButtonView.frame = newf;
}

Hope this helps.. :)