1.设置分割线风格(对于自定义cell,如果cell左边顶部有空隙需要以下代码调整)
在- (void)viewDidLoad里面写
myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
-(void)viewDidLayoutSubviews
{
// 重写UITableView的方法是分割线从最左侧开始
if ([myTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[myTableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([myTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[myTableView setLayoutMargins:UIEdgeInsetsZero];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
2.设置分割线的颜色:
[myTableView setSeparatorColor:[UIColor colorWithRed:68.0/255.0 green:68.0/255.0 blue:68.0/255.0 alpha:1.0]];
3.隐藏多余cell方法
-(void)setExtraCellLineHidden: (UITableView *)tableView
{
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:view];
}