Reputation: 43
I've created a UITableView and have a problem with the separator. I customized it so that it appears gray and without inset :
self.tableView.separatorInset = .zero
self.tableView.separatorColor = AppColors.separatorColor
I also tried with an image :
self.tableView.separatorInset = .zero
tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
tableView.separatorColor = UIColor(patternImage: #imageLiteral(resourceName: "thin_divider"))
Problem : When a row is selected, the separator becomes white. I played with didSelectRowAt, didDeselectRowAt and didHighlightRowAt but nothing to do, it stays white when the cell is selected. See the example below (last cell is selected on this example)...
Upvotes: 4
Views: 1324
Reputation: 14118
Try this code line in cellForRowAtIndexPath
method
[cell setSelectionStyle: UITableViewCellSelectionStyleNone];
This will set none as the selection style (default value for this property is UITableViewCellSelectionStyleBlue
).
For cell highlight part, use below code in didSelectRowAtIndexPath
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setHighlighted: NO];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Hope this helps.
Upvotes: 3