lehn0058 lehn0058 - 1 year ago 66
iOS Question

Setting corner radius on a cell kills UICollectionView's performance

I have a

that has only a few cells (about 20). Performance for this collection works great. However, as soon as I try to round the corners of the
that are being rendered by this view, my performance takes a significant hit. In my cell's init method, this is the only line I add to cause this:

[self.layer setCornerRadius:15];

Since this is in the init method and I am reusing the cells properly, I don't see why this should be causing me issue.

I have tried adjusting the rasterization and opacity of the sell using multiple combinations of the following, with still no effect:

[self.layer setMasksToBounds:YES];
[self.layer setCornerRadius:15];
[self.layer setRasterizationScale:[[UIScreen mainScreen] scale]];
self.layer.shouldRasterize = YES;
self.layer.opaque = YES;

Is their some setting or trick to improve the performance of a
that has cells with rounded corners?

Answer Source

As @Till noted in comments, a prerendered image should solve your performance problem. You can put all the corner rounding, shadowing, and whatever other special effects into that instead of needing CA to render them on the fly.

Prerendered images don't lock you into a static content size, either: look into the UIImage resizable image stuff. (That's still way faster than CA rendering every frame.)