11

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?

4

2 回答 2

21

解决了,但我无法解释原因。

交换两个语句的顺序。先设置颜色,再设置插图:

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

一切正常:

在此处输入图像描述

于 2013-10-01T22:36:26.403 回答
2

尝试将此添加到 cellForRowAtIndexPath。以及设置 tableView 的 separatorInsets。

cell.separatorInset = UIEdgeInsetsZero;

来自 UITableViewCell iOS 文档:

@property (nonatomic) UIEdgeInsets separatorInset

单元格内容的插入值。

您可以使用此属性在当前单元格的内容与表格的左右边缘之间添加空格。正插入值将单元格内容和单元格分隔符向内移动并远离表格边缘。负值被视为插入设置为 0。

于 2014-04-09T20:05:58.800 回答