Question

If I set a red separatorColor on a table view in iOS 7 and also set the separatorInset to UIEdgeInsetsZero or any other custom inset value, all additional or "extra" rows have default colored separators. How can I fix this?

The last sentence of the documentation on separatorInset implies that it somehow controls the extra records, but I don't see how:

In iOS 7 and later, cell separators do not extend all the way to the edge of the table view. This property sets the default inset for all cells in the table, much like rowHeight sets the default height for cells. It is also used for managing the "extra" separators drawn at the bottom of the plain style tables.

Set the separator in viewDidLoad:

self.tableView.separatorColor = [UIColor redColor];

And you get this:

enter image description here

And when you set the separatorInset and a color:

self.tableView.separatorInset = UIEdgeInsetsZero;    // <- any custom inset will do
self.tableView.separatorColor = [UIColor redColor];

You get this:

enter image description here

Why does this happen and how can I make all the separators red and set all the separator insets to zero? Is this a bug?

Was it helpful?

Solution

Solved it, but I can't explain why.

Swap the order of the two statements. Set the color first, then the inset:

self.tableView.separatorColor = [UIColor redColor];
self.tableView.separatorInset = UIEdgeInsetsZero;

Everything works:

enter image description here

OTHER TIPS

Try adding this to cellForRowAtIndexPath. As well as setting the tableView's separatorInsets.

cell.separatorInset = UIEdgeInsetsZero;

From the UITableViewCell iOS Docs:

@property (nonatomic) UIEdgeInsets separatorInset

The inset values for the cell’s content.

You can use this property to add space between the current cell’s contents and the left and right edges of the table. Positive inset values move the cell content and cell separator inward and away from the table edges. Negative values are treated as if the inset is set to 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top