Timo Cengiz Timo Cengiz - 5 months ago 187
iOS Question

How to set the full width of separator in UITableView

So i have a UITableView where the separators don't have the full width. It ends like 10 pixels before the left side. I was playing around with this code in the viewDidLoad

self.tableView.layoutMargins = UIEdgeInsetsZero;


also in the storyboard when you can select custom or default selectors. Now all the cells that are populated don't have the full width selectors but the cells that are empty have full width.

How on earth can i fix this?

Thanks for all the help

Answer

Ok i found the answer. Don't know why i didn't come across this post before but of course after you post a question then suddenly the right post just appears ahead of you. I got the answer from this post: iOS 8 UITableView separator inset 0 not working

Just add this code on your TableViewController

-(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];
    }
}

-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }

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