Search code examples
iosswiftuitableviewshadowshadowpath

Shadow on UITableViewCell is giving bad performance


I'm creating table view with custom cells, which looks like news feed - on gray background there are rectangles with rounded corners and shadow.

While cellForRowAtIndexPath method is calling I'm setting shadow like this:

cell.postCard.layer.cornerRadius = 3
cell.postCard.layer.shadowColor = UIColor.darkGrayColor().CGColor
cell.postCard.layer.shadowOffset = CGSizeMake(0,1)
cell.postCard.layer.shadowRadius = 3
cell.postCard.layer.shadowOpacity = 0.5
cell.layer.shadowPath = UIBezierPath(rect: cell.postCard.layer.bounds).CGPath

Where postCard is UIView - it's container for all context of cell.

I've read that I need to add shadowPath to get good performance but I think it's not working because when I'm slowly moving table view is stuttering. Can be reason of using simulator than real device?


Solution

  • You are setting shadow path to cell's layer, while modifying shadow settings for cell.postCard

    cell.postCard.layer.shadowOpacity = 0.5
    cell.layer.shadowPath = UIBezierPath(rect: cell.postCard.layer.bounds).CGPath
    

    Is this really what you need?