Bad_Developer
Bad_Developer

Reputation: 537

UICollectionView dynamic width based on number of items inside it?


I'm currently wanna create an floating UICollectionView on screen which can change width whenever number of items inside it changed.
For example:
I'm prefer to make it with max width = 280px
If numberOfItems = 2, my UICollectionView width will fit with items inside it, and it will increase width till numberOfItems = 4, If numberOfItems > 4, it's will enable scrolling horizontally.
Does someone has made it before? Please help me.
Thanks in advance.
edit: I'm updated image about the collection view, currently it's only have 2 items while width = 280. enter image description here

Upvotes: 0

Views: 243

Answers (1)

Stas Volskiy
Stas Volskiy

Reputation: 451

enter image description here

I think that is something you are looking for. Check out my test project to see how it works. You have to change width constraint only.

Upvotes: 1

Related Questions