分隔线前的空格进入我的TableView [英] White space before separator line into my TableView

查看:84
本文介绍了分隔线前的空格进入我的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:



Update - Below code works on iOS 7 and 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆