Change color of inset area in UITableView separator Change color of inset area in UITableView separator ios ios

Change color of inset area in UITableView separator


Setting the cell's background colour to the same as the contentView's background colour seems to give the best results.

cell.backgroundColor = cell.contentView.backgroundColor;

That will handle cases where the accessoryView is the wrong colour as well.


So I just had this problem myself, and it's strange because it seems to work fine on some tableviews. I'm assuming that the grey color you are using is the background color of your tableview. If not, this solution may not work.

It seems like cells in iOS 7 don't always pick up the tableview background color when a separator inset is present, so you need to manually set the cell background to clearColor. Interestingly, setting this value in storyboards didn't work for me, I had to do it in code. Add this:

cell.backgroundColor = [UIColor clearColor];

when you configure the cell in this delegate function:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


It's the default in iOS 7. But you can change it to the way iOS 6 looks. Please try my code below. You will be amazed:

    tableView.separatorColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];    NSString *iosversion = [[UIDevice currentDevice] systemVersion];    int version = [iosversion intValue];    if(version>6)    {        tableView.separatorInset = UIEdgeInsetsZero;    }

Swift 3+:

tableView.separatorInset = UIEdgeInsets.zero