UITableView with static cell - different separation color per section?

I have UITableView with static cells in 4 sections done in Storyboard. However, I want to change the separator color for one section ([UIColor clearColor]). How can I do that??? Is it actually possible?

I can set the separatorColor to clearColor for the entire table, but not only for one specific section.

Screenshot of table view section:

Answers


AFAIK there is no method for this. But you can put a background image to the cell which has a separator at the bottom and set separatorstyle to UITableViewCellSeparatorStyleNone. So you have your own separator in every cell.


Maybe you can achieve your goal by setting the header text for the section to an empty string.


One approach would to create your own UIView subclass and do your own custom drawing in drawRect:. You would take this view and add it as the backgroundView of your table view cell. Something like this:

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 1.0);

    // Draw black line
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    CGFloat components[] = {0.0, 0.0, 0.0, 0.3};
    CGColorRef blackColor = CGColorCreate(colorspace, components);

    CGContextSetStrokeColorWithColor(context, blackColor);

    CGContextMoveToPoint(context, 0, rect.size.height - 1.5);
    CGContextAddLineToPoint(context, rect.size.width, rect.size.height - 1.5);
    CGContextStrokePath(context);
    CGColorRelease(blackColor);

    // Draw white bottom line
    CGFloat whiteComponents[] = {1.0, 1.0, 1.0, 0.75f};
    CGColorRef whiteColor = CGColorCreate(colorspace, whiteComponents);

    CGContextSetStrokeColorWithColor(context, whiteColor);

    CGContextMoveToPoint(context, 0, rect.size.height - 0.5);
    CGContextAddLineToPoint(context, rect.size.width, rect.size.height - 0.5);
    CGContextStrokePath(context);
    CGColorRelease(whiteColor);

    // Draw top white line
    CGFloat whiteTransparentComponents[] = {1.0, 1.0, 1.0, 0.45};
    CGColorRef whiteTransparentColor = CGColorCreate(colorspace, whiteTransparentComponents);

    CGContextSetStrokeColorWithColor(context, whiteTransparentColor);

    CGContextMoveToPoint(context, 0, 0.5);
    CGContextAddLineToPoint(context, rect.size.width, 0.5);
    CGContextStrokePath(context);
    CGColorRelease(whiteTransparentColor);



    CGColorSpaceRelease(colorspace);
}

Need Your Help

PHP: strtotime formatting

php timestamp strtotime

I am trying to put a readable time and date as part of a file name (in php). I am having all kinds of trouble with this and was hoping someone could help. I have tried several different recommendat...