0

We are trying to resolve the warning for ScrollView "needs constraint for y position or height"

The scrollView has

  • a card View which has dynamic content inside, e.g. various text that expands with accessibility
  • a tableview with undetermined number of cells whose content can also expand with accessibility

So far we can only put >= height constraint for the tableView/cardView, but the scrollView doesn't know the exact height of its subcomponents so it can't calculate itself.

However, even with the warning, it does run fine and as expected.

An alternative strategy we've tried is to put an explicit height on the the tableView, let's say 500, then when the view has loaded, get the calculated content size and set height = actual content size.

Is there a better way to handle height constraints for ScrollView with dynamic content inside?

user1869558
  • 697
  • 3
  • 11
  • 21
  • 1
    It sounds like you're laying out your scroll view in Storyboard / Interface Builder, and then adding "dynamic content"? If so, you can set an **Intrinsic Size Placeholder** to satisfy IB. – DonMag Sep 09 '22 at 20:08

1 Answers1

0

DonMag is right. I was not aware of the Intrinsic Size: PlaceHolder but that is the exact solution to my problem.

For those looking, it will be at the bottom of the Size Inspector, the second last IB Inspectors pane.

This topic should help anyone else:

What is the difference of intrinsic size vs system width/height constraints?

user1869558
  • 697
  • 3
  • 11
  • 21