Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have UITableView separator appear below imageView

So I have a checklist type of thing going. However I decided to have the checkmarks appear on the left side of my cells. To accomplish this I am having each cell show a checkmark png image with cell.imageView?.image = UIImage(named: "check"). This is working fine, however I am running into the problem where the separator line does not appear below the check mark as shown below. I don't like how this looks since the empty cell separators extend the whole length of the cell. Any suggestions to make the separator visible below the image?

like image 938
boidkan Avatar asked Oct 09 '14 17:10

boidkan


2 Answers

You can also change this in Storyboard:

When selecting the table view cell, change Separator to Custom Insets and fill in the desired insets.

enter image description here

like image 193
Pieter Meiresone Avatar answered Sep 29 '22 23:09

Pieter Meiresone


Add this method to the data source of your table view:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    cell.separatorInset = .zero
  }

or do the same thing in the -tableView:cellForRowAtIndexPath: method.

For Objective-C:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    [cell setSeparatorInset:UIEdgeInsetsZero];
}
like image 21
Sandeep Avatar answered Sep 29 '22 23:09

Sandeep