1

I'm building something as shown in the image below:

horizontal list

I'll try to explain a bit more what my goal is. I have a UITableView. One UITableViewCell (1) in here will contain a title (left out in this image) and a UICollectionView (2) (same width as tableview/screen). This collectionview uses a subclass of UICollectionViewLayout to make it horizontally scrollable, evenly spacing the items.

Each UICollectionViewCell (3) in here contain a title and description, both with dynamic heights. Also, this cell contains a new collectionview (4). This new collectionview contains a number of items (5). In this most inner collectionview a row can contain a maximum of 5 items.

Currently I have a tableviewcell (1) with horizontally scrollable collectionview (2), putting the items (3) next to each other. I also have the most inner collectionview (4) putting the items (5) in the correct way.

The difficulty I'm facing now is:

  • To dynamically size the height of collectionview (4), depending on how many rows for the items are needed, so depending on the number of items.
  • To dynamically size the height of collectionviewcell (3), depending on the height of the title, description and collectionview (4).
  • If possible, to dynamically size the height of the collectionview (2) and the tableviewcell (1) containing this, as high as the biggest cell (3).

I hope someone would have an idea how to do this, if it is even possible. I do hope so, while keeping the code 'easy' to follow.

I can do a lot with constraints / autolayout, but this I can't get my head around.

Jeroen
  • 1,842
  • 2
  • 21
  • 43
  • 2
    I wouldn't get caught up on dynamically sizing content. It's not too tough. I would recommend you break your problem down into bite size chunks starting from the innermost views outward. Make use of stack views. Less is more on the constraints. https://stackoverflow.com/a/38028106/4475605 – Adrian Feb 02 '19 at 01:36
  • Wow, how I didn't know about the existence of `UIStackView`? I'll check that out! And yes, I'll try again starting on the innermost view. My biggest question now is how to give a `UICollectionView` a dynamic height. Thanks! – Jeroen Feb 02 '19 at 22:11

0 Answers0