iOS cell封装最后一行分隔线左间距为0

UITableViewController.m

NSString *identifier = @"cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
Model *model = [[Model alloc] init];

cell.isLast = [model isEqual:self.array.lastObject];

Cell.h

@property (nonatomic, assign) BOOL isLast;

Cell.m

- (void)setIsLast:(BOOL)isLast
{
    if (isLast == YES) {//最后一行
        
        if ([self respondsToSelector:@selector(setSeparatorInset:)])
        {
            [self setSeparatorInset:UIEdgeInsetsZero];
        }
        if ([self respondsToSelector:@selector(setLayoutMargins:)])
        {
            [self setLayoutMargins:UIEdgeInsetsZero];
        }
        if([self respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)])
        {
            [self setPreservesSuperviewLayoutMargins:NO];
        }
    }
    else
    {
        [self setSeparatorInset: UIEdgeInsetsMake(0, 10, 0, 0)];
    }
}

你可能感兴趣的:(iOS cell封装最后一行分隔线左间距为0)