0
votes

I have a custom tableview cell subclass which draws a drop shadow... Views First Load

When I scroll down, some of the cells do not have their shadows drawn...

enter image description here

This also happens when I scroll back up.

I have tried moving the drawing code to the cell subclasses drawRect, setNeedsLayout. I have also tried this in the tableviewController's configure cell method.

self.layer.shadowRadius = 4.1f;
self.layer.shadowOpacity = 0.5;
self.layer.shadowOffset = CGSizeMake(2.1f,7.4f);

CGFloat curlFactor = 15.00f;
CGFloat shadowDepth = 4.6f;
CGSize size = self.layer.bounds.size;

UIBezierPath* path = [UIBezierPath bezierPath];

[path moveToPoint:CGPointMake(0.0f, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, size.height + shadowDepth)];

[path addCurveToPoint:CGPointMake(0.0f, size.height + shadowDepth)
        controlPoint1:CGPointMake(size.width - curlFactor, size.height + shadowDepth - curlFactor)
        controlPoint2:CGPointMake(curlFactor, size.height + shadowDepth - curlFactor)];
[self.layer setShadowPath:[path CGPath]];

Thanks in advance.

1

1 Answers

0
votes

It looks like you are drawing shadows out of bounds of each UITableViewCell view, when UITableView is reusing cells and displaying them, it may not keep all cell subviews stacked over each other perfectly and you need to ensure them yourself.

in UITableView delegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    static int index = -1;
    if (indexPath.row > index) {
        [tableView sendSubviewToBack:cell];
    }
    else {
        [tableView bringSubviewToFront:cell];
    }
    index = indexPath.row;
}

or you can implment inner shadow and avoid drawing outside of bounds.