设置设置UITableViewCell中的分割线顶格显示有三种方式:
1、直接在tableview的代理方法cellForRowAtIndexPath:(NSIndexPath *)indexPath中设置,这种是最简单的方法:
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
2、这种方式比较麻烦:
-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
3、在自定义cell中自己自定义,可以设置不同宽度颜色的分割线