UItableview分隔线的高度

时间:2014-09-25 04:38:38

标签: ios uitableview list-separator

我可以调整UITableview分隔线的高度吗?我在单元格中添加UIView作为分隔线并且它很好,问题是当我滑动单元格以删除它时,删除按钮是问题,它与分隔线重叠,或者我可以调整删除按钮的高度?

separator line delete

enter image description here

4 个答案:

答案 0 :(得分:1)

Rashad粘贴的代码很旧(找到here)并且似乎不适用于iOS 7或iOS 8。

以下是有效的更新代码:

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

答案 1 :(得分:0)

我总是在cellView的contentView上绘制分隔线,就像子视图一样。并禁用tableView中的separatorStyle。并自定义删除按钮,如下所示:https://stackoverflow.com/a/22396248/887325

答案 2 :(得分:0)

在你的TableViewCell layoutSubviews方法中写下这个:

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

希望这会有所帮助.. :)

答案 3 :(得分:0)

如果您无法调整删除按钮的大小,请调整底部UIView的大小,使其与删除按钮重叠。