user5762284
user5762284

Reputation:

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?

Upvotes: 1

Views: 1436

Answers (3)

Oleg Gordiichuk
Oleg Gordiichuk

Reputation: 15512

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.

Upvotes: 0

user2990759
user2990759

Reputation: 127

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

Upvotes: 0

Shaman
Shaman

Reputation: 61

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?

Upvotes: 1

Related Questions