UItableview Separator line's height

◇◆丶佛笑我妖孽 提交于 2019-12-25 06:53:02

问题


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



来源:https://stackoverflow.com/questions/26030638/uitableview-separator-lines-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!