需求:一条分割线,把第一个cell,和第二个cell分割开来,设置背景类似灰色吧。但其他cell的底部线条不变,并且有间距。因为默认的底部线条是有间距的,分割线的背景view设置背景的话,就会出现高低不齐的情况,需要修改间距为0
-
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIEdgeInsets edge = UIEdgeInsetsMake(0, 15, 0, 15);//修改第一个cell和第二个cell的底部线条间距为0,左对齐
if ( indexPath.row == 1||indexPath.row==0) {
edge = UIEdgeInsetsMake(0, 0, 0, 0);
}if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:edge];
}if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:edge];
}
}