Scrollable lists using Protocol-Oriented Programming and UICollectionViewFlowLayout

Boris Bugor
9 min readAug 19, 2023
Photo by Pavel Neznanov on Unsplash

Each developer in practice faced the need to make up a screen based on a scrolling list of elements. Or maybe not just one list, but several.

It can be horizontal lists, vertical lists, lists with a complex layout. These can be lists with a predetermined size, or with a dynamic size. And the developer always has a choice — to use UITableView or UICollectionView. (We will not consider UIScrollView, since its use is limited to a finite list of a predetermined number).

Each of the above options has strengths and weaknesses:

  • UITableView, one of the advantages of which is the dynamic calculation of the content height out of the box, is used in vertical lists.
  • UICollectionView — always had more use cases chronologically, as they always covered more scroll direction. However, their biggest drawback prior to iOS 13 is the static size, which had to be calculated manually.

And as every developer knows, after choosing one or the other, the next step is to write a tangible amount of accompanying code in order to make this list work.

  • You have to register cells, headers, footers or a runtime crash is inevitable;
  • You have to monotonously create cells, configure their…

--

--