iosobjective-cuitableviewseparatorinsets

UITableViewCell separator insets don't work when table.width is much greater than view.width


UITableViewCell separator insets don't work when table.width is much greater than view.width on iOS 10, I haven't try it on the device which iOS version is less then iOS 10.

enter image description here

code is here on gist


Solution

  • There are two ways in which you can solve this problem.

    First one you can add a separator line view in cell content view.

     UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableview.frame.size.width, 3)];      
     line.backgroundColor = [UIColor whiteColor];
    
    [cell.contentView addSubview:line];
    

    The second one is apple provided one and pretty easy also just add this line of code where u declare your tableview

    yourTableView.cellLayoutMarginsFollowReadableWidth = NO;