How to remove the last border of the last cell in UITableView?
Solution 1:
The best solution is add a footer view. The following code hide the last cell's line perfectly:
Objective-C
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1)];
Swift 4.0
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1))
Solution 2:
In iOS 7 there is an easier solution. Supposing cell is your last cell:
cell.separatorInset = UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0);
Solution 3:
Updated on 9/14/15. My original answer become obsolete, but it is still a universal solution for all iOS versions:
You can hide tableView
's standard separator line, and add your custom line at the top of each cell. The easiest way to add custom separator is to add simple UIView
of 1px height:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.bounds.size.width, 1)];
separatorLineView.backgroundColor = [UIColor grayColor];
[cell.contentView addSubview:separatorLineView];
To date, I subscribe to another way for hiding extra separators below cells (works for iOS 6.1+):
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];