我正在自定义一个 UITableView
。我想隐藏 last 单元格上的分隔线...我可以这样做吗?
我知道我可以做到 tableView.separatorStyle = UITableViewCellStyle.None
但这会影响 所有 tableView 的单元格。我希望它只影响我的最后一个单元格。
最佳答案
在viewDidLoad
中,添加这一行:
self.tableView.separatorColor = [UIColor clearColor];
在cellForRowAtIndexPath
中:
适用于 iOS 较低版本
if(indexPath.row != self.newCarArray.count-1){
UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 2)];
line.backgroundColor = [UIColor redColor];
[cell addSubview:line];
}
适用于 iOS 7 更高版本(包括 iOS 8)
if (indexPath.row == self.newCarArray.count-1) {
cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f);
}
https://stackoverflow.com/questions/8561774/