I have a horizontal stack view in a UICollectionViewCell. There a four items in the stack view, the first three are specialized UILabels (seen as "loose", "$?", and a score of 75), I never want to be compressed. The final item is a specialized UITextView that can list any number of user defined tags, and so can be a very long list.

The first time the cell is used, it lays out everything correctly. Correct layout

But when the cell gets re-used, some of the first two items will be compressed. These are the results with default settings, but I tried various combinations of hugging/compression priority but it never seems to have the correct result. Am I just approaching this incorrectly?

Bad layout

Edit: Some setup info: stack view settings

stack view constraints

1

There are 1 best solutions below

1
DonMag On

If I understand your layout correctly...

  • "Loose" "$?" and "75" are each a custom UILabel
  • "Shell" "A" "C" etc... are custom characters / elements in a custom UITextView

It's not clear, however, what should happen when you have too many "tags" to fit in the horizontal space of the custom text view.

Regardless, if you want the first three elements (custom labels) to always display as they are - no stretching, no compression...

Leave the stack view settings as you have them:

Axis: Horizontal
Alignment: Fill
Distribution: Fill
Spacing: 5

And use these Content Priority settings (the translucent light-blue rectangle is the frame of the custom text view):

enter image description here