How to change partition-based separator colors

I have two sections in my table view. I used the setSeparatorColor property to change the color of the separator. This actually changes the color of both sections. Is it possible to change the color of the separator based on the section?

+3
source share
2 answers

You can do this by adding two single-pixel subselections just above and below your cell so that they appear on top of the UITableView separator. Here are the specifics:

  • Subclass UITableViewCell with the IBOutlet UIView * topSeparator property and the IBOutlet UIView * bottomSeparator property.

  • Set cell.clipsToBounds to NO.

  • topSeparator CGRectMake (0.0f, -1.0f, cell.width, 1.0) backgroundColor, . ( 10 .)

  • bottomSeparator CGRectMake (0.0f, cell.height, cell.width, 1.0) backgroundColor, . ( 10 .)

  • topSeparator.hidden = YES; bottomSeparator.hidden = NO;.

  • topSeparator.hidden = NO; bottomSeparator.hidden = YES;.

  • topSeparator.hidden = NO; bottomSeparator.hidden = NO;

, , UITableView , .

+1

"didSelectRowAtIndexPath"

.

- , .

0

Source: https://habr.com/ru/post/1740736/


All Articles