1

I have a tableview cell that contains a horizontal UIStackView. Inside it is an UIImageView (on the left, 100x100 dimensions) and a vertical UIStackView (on the right) that contains 4 labels. The vertical UIStackView is constrained to the UIImageView's top and bottom anchors. But the bottom constraint is "less than or equal to".

I am setting the text property on these labels but if the text is nil I hide that label. Stack View than sets the height of that label to 0 and it doesn't appear in the Stack View. Now the idea is if some labels are hidden, the combined intrinsic content size's of the remaining labels will define the height of the vertical UIStackView and it will decrease in height based on that "less than or equal to" bottom constraint.

This doesn't work though. Take the case where the 2nd and 4th labels have been hidden. The 1st label is normal height. But the 3rd label stretches all the way down to the bottom of the UIImageView. This is in contrast to my expectation that the intrinsic content sizes of the labels would be less and the label's UIStackView would shrink.

I'm guessing there is some priorities that might need to be tuned to get this working properly. This whole view hierarchy is contained in a UITableViewCell and that has dynamic height applied which I hope doesn't cause any problems.

So if the intended behavior is that when I hide labels the vertical UIStackView shrinks, what constraints must I add/delete or which priorities must be set?

Alex Bollbach
  • 4,370
  • 9
  • 32
  • 80
  • to clarify/sum this up a bit, i believe its a fight between the intrinsic content size (height) of on of the two labels in the vertical stack-view and that "less than or equal to" constraint between the bottom of the stack view and the image view. in other words, is it true that if label one and label three have combined intrinsic content height's of 25 and 25 and therefore 50 is < the image-view height, does the vertical stack view compress and become "less than" that bottom anchor on the image-view? – Alex Bollbach Jul 19 '17 at 20:11

0 Answers0