Faster way to estimate cell height in a CollectionView

老子叫甜甜 提交于 2019-12-03 20:36:35

Ideally you should not use systemLayoutSizeFitting in your sizeForItemAt, because, as you say, it is slow.

You could precache some cell data, calculate the sizes, and store them in an array or similar, so that sizeForItemAt merely has to do the lookup in the array — which is fast.

And you don't really need to use systemLayoutSizeFitting, either; you can use your knowledge of the label size and contents to calculate the size (e.g. using NSAttributedString measurement methods).

That is what we used to do before systemLayoutSizeFitting or auto layout existed, and it remains far faster.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!