White space before separator line into my TableVie

2019-01-10 05:32发布

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:

enter image description here

Why? It is a default visualize? Can I change something to remove this white left padding?

8条回答
成全新的幸福
2楼-- · 2019-01-10 05:54

Use below code to remove the unwanted padding in UITableView. It works on both IOS 8 & 7

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell     forRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    } 

    if ([tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
查看更多
Luminary・发光体
3楼-- · 2019-01-10 06:01

This did the trick for me:

cell?.layoutMargins = UIEdgeInsetsZero;
cell?.preservesSuperviewLayoutMargins = false
查看更多
登录 后发表回答