- 方式1.自定义分割线
- 方式2.利用系统属性(iOS6->iOS7 , iOS7 -> iOS8)不能支持iOS8
// 设置分割线占据全屏----iOS6->iOS7
self.tableView.separatorInset = UIEdgeInsetsZero;
// iOS7 -> iOS8
cell.layoutMargins = UIEdgeInsetsZero;
- 方式3
- 1.取消系统的分割线
- 2.设置tableView背景色为分割线颜色
- 3.重写cell的setFrame
// 1.取消系统分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// 2.设置tableView背景色
self.tableView.backgroundColor = XMGColor(215, 215, 215);
// 3.在自定义cell的.m里重写该方法
- (void)setFrame:(CGRect)frame
{
frame.size.height -= 1;
// 给cellframe赋值
[super setFrame:frame];
}
方式4
这三个方法并用,实现自定义分割线效果,完全一条线显示
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
// 三个方法并用,实现自定义分割线效果
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
cell.separatorInset = insets;
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:insets];
}
if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
[cell setPreservesSuperviewLayoutMargins:NO];
}
}