UItableview Separator line's height

2019-09-18 06:22发布

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?

separator linedelete

enter image description here

4条回答
ら.Afraid
2楼-- · 2019-09-18 06:28

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

查看更多
Summer. ? 凉城
3楼-- · 2019-09-18 06:35

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;
}
查看更多
淡お忘
4楼-- · 2019-09-18 06:44

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.. :)

查看更多
爷的心禁止访问
5楼-- · 2019-09-18 06:47

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

查看更多
登录 后发表回答