分隔线前的空白进入我的 TableView [英] White space before separator line into my TableView
问题描述
我有一个关于 UITableView 的问题...我有一个 UITableViewController 并且我创建了一个自定义单元格.当我将 tableView 可视化时,我会在分隔线之前看到一点空白,如您在此屏幕截图中所见:
I have a question about UITableView... I have a UITableViewController and I created a custom cell. When I visualize the tableView I see a little white space before the separator line as you can see into this screenshot:
为什么?它是默认的可视化?我可以改变一些东西来移除这个白色的左填充吗?
Why? It is a default visualize? Can I change something to remove this white left padding?
推荐答案
iOS 7 中默认提供前导空格,即使是自定义单元格也是如此.
The leading whitespace is provided by default in iOS 7, even for custom cells.
检查 UITableviewCell 的此属性 separatorInset
以删除/添加单元格行分隔符两端的空白.
Checkout this property separatorInset
of UITableviewCell to remove/add white spacing at either ends of cell's line separator.
//去除空格
cell.separatorInset = UIEdgeInsetsZero;
或者,在 UITableView 级别,您可以使用此属性 -
Alternatively, at UITableView level, you can use this property -
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { // Safety check for below iOS 7
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
更新 - 以下代码适用于 iOS 7 和 iOS 8:
-(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 *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
这篇关于分隔线前的空白进入我的 TableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!