0

I'm trying to make separators with 20 pt insets from left and right. whatever I do I still get a full line from one edge to the other.

what I tried: In attributes inspector choose separator - Custom Inset and added 20 pixel from left and right.

I also tried in viewDidLoad -

self.tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
self.tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20)

I still get a full line.. any help will be appreciated thanks

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
user101010
  • 543
  • 1
  • 5
  • 12

2 Answers2

0

Do setSeparatorInset in willDisplayCell,

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
           [cell setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
    }
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 20, 0, 20)];
    }
}

Reference : iOS 8 UITableView separator inset 0 not working

Community
  • 1
  • 1
Venk
  • 5,949
  • 9
  • 41
  • 52
0

You can set separator insets in interface builder as well

Go to attribute inspector there you change under separator inset to the value whatever u want

Abi
  • 501
  • 4
  • 6