1

I set up a table view in Interface Builder, with Separator set to Single Line, and in the data source class I have this code:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { UIImageView *topCellBackgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg-top"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)]]; cell.backgroundView = topCellBackgroundImageView; } // If it's the last row else if (indexPath.row == ([tableView numberOfRowsInSection:0] - 1)) { UIImageView *bottomCellBackgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg-bottom"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)]]; cell.backgroundView = bottomCellBackgroundImageView; } else { UIImageView *middleCellBackgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(3.0, 3.0, 3.0, 3.0)]]; cell.backgroundView = middleCellBackgroundImageView; } } 

And in viewDidLoad I do:

- (void)viewDidLoad { [super viewDidLoad]; self.tableView.separatorColor = [UIColor redColor]; self.tableView.backgroundView = nil; self.tableView.backgroundColor = [UIColor colorWithRed:245/255.0 green:244/255.0 blue:240/255.0 alpha:1.0]; } 

But the border color never shows up. I tried setting them in the images, but obviously that presents a lot of centering issues with the images, and having their borders overlap.

UPDATE:

After looking around a bit more, it does indeed get set, but it seems that setting the cell's backgroundView puts what you set as the backgroundView over the separatorColor. When I remove the willDisplayCell: method, the red color shows up fine (same when I select the cell even with the backgroundView set, it will show red until I unselect it). The question is, how can I set the separatorColor if I have a backgroundView set?

2
  • Looks dandy to me. self.tableView is not nil, right? Maybe try putting a breakpoint somewhere and printing the value in your console to see if something changed it somehow? Commented Jul 6, 2013 at 19:59
  • After looking around a bit more, it does indeed get set, but it seems that setting the cell's backgroundView puts what you set as the backgroundView over the separatorColor. When I remove the willDisplayCell: method, the red color shows up fine (same when I select the cell even with the backgroundView set, it will show red until I unselect it). The question is, how can I set the separatorColor if I have a backgroundView set? Commented Jul 6, 2013 at 20:34

1 Answer 1

2

One trick you can use is to add a UIView to your background view with a red background color and height 1 point. Another option is to ask your designer to incorporate such a red line in the image file for the background view.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm the designer as well, and I've tried adding the border to the images themselves, but the issue with that lies in the fact that the cells don't overlap at all, so when you give them all a border, there's a 2px border between the items. This can be circumvented by removing the top border on some of the images, but then some have different heights.
I'd recommend only to have the separator at the bottom of each image. Since you're already using resizable images different heights should not be a problem. Just make sure that the border pixel are inside the non-resizable caps.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.