Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of inset area in UITableView separator

I have a customized UITableView, the cells have a different background color (set in a custom backgroundView). However, the background color is only applied within the cell, but not extended to the inset area of the separator. As you can see in the screenshot, there is a white area to the left of the colored separator.

How can we change the color of this white line? We would like to make the line "disappear" by setting it to the same color as the cell background. Thanks!

enter image description here

like image 518
zavié Avatar asked Mar 06 '14 12:03

zavié


2 Answers

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.

like image 188
Dave Wood Avatar answered Sep 25 '22 17:09

Dave Wood


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 
like image 26
jzn Avatar answered Sep 26 '22 17:09

jzn