1

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?

3 Answers3

1

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?

Shaman
  • 61
  • 5
  • Yeah, it wasn't my intention. Fortunately it improved performance, but the shadow is not correctly sized, I mean its smaller than postCard. –  Jan 15 '16 at 20:05
  • You always can play with the shadow size in by increasing the rect. Use CGRectInset: rect = CGRectInset(rect, -increaseBy, -increaseBy) – Shaman Jan 15 '16 at 21:35
  • Height for the cells is dynamically creating. Some of the cells has shadow in a background in good size, I don't know why it's not woring –  Jan 15 '16 at 21:50
0

Also, you should set 'cell.clipsToBounds = false' for your cell.

user2990759
  • 127
  • 1
  • 5
0

Try to read about the should​Rasterize and how it is working with shadows and corner radius of the UI elements. You can boost performance by manipulation of the should​Rasterize value.

Oleg Gordiichuk
  • 15,240
  • 7
  • 60
  • 100