views:

169

answers:

2

Hi,

I am having two section in my table view. I used the setSeperatorColor property to change the color of the seperator. It is actually changing the color of both the sections. Is it possible to change the seperator color based on the section ?

A: 

Hi, thndrkiss

try to change the seperator color in the method "didSelectRowAtIndexPath"

it will effect at the selection time.

if any dought then leave comment.

yakub_moriss
:( No. It is not working. [self.tableView setSeperatorColor:[UIColor greenColor]];
thndrkiss
try to apply TintColor function
yakub_moriss
+1  A: 

You can accomplish this by adding two one-pixel high subviews just above and below your cell so that they render on top of the UITableView's separator. Here are the specifics:

  1. Create a UITableViewCell subclass with an IBOutlet UIView *topSeparator property and an IBOutlet UIView *bottomSeparator property.

  2. Set your cell.clipsToBounds to NO.

  3. Construct topSeparator with a frame of CGRectMake(0.0f, -1.0f, cell.width, 1.0), and a backgroundColor set to your desired separator color. (Reduce width by 10px on left and right for grouped cells.)

  4. Construct bottomSeparator with a frame of CGRectMake(0.0f, cell.height, cell.width, 1.0), and a backgroundColor set to your desired separator color. (Reduce width by 10px on left and right for grouped cells.)

  5. When returning the first cell in the section, set topSeparator.hidden = YES; bottomSeparator.hidden = NO;.

  6. When returning the last cell in the section, set topSeparator.hidden = NO; bottomSeparator.hidden = YES;.

  7. When returning all other cells in the section, set topSeparator.hidden = NO; bottomSeparator.hidden = NO;

You need separators on both the top and bottom to ensure that one of them renders on top of the UITableView's separator whether you're scrolling up or down.

cduhn
i just created few images and set them as background to show section separators.
thndrkiss