3

I have to display multiple views inside a single view controller. I have added a scroll view and added the views through the interface builder. Constraints added to all four sides as well.

enter image description here

Each label (green label) and view (gray view) is embedded in a UIStackView. I have set the leading, top, trailing and height constraints added to each stack view. No auto layout issues/warnings in Xcode.

But when I run the app, it shows up like this.

enter image description here

Why doesn't the stackview get the width according to the leading and trailing constraints I've set?

Isuru
  • 30,617
  • 60
  • 187
  • 303

1 Answers1

3

You need to add three more constraints.

  1. Pin width of A Stack View equal to superview -16.
  2. Pin width of B = width of A
  3. Pin width of C = width of B

enter image description here

BangOperator
  • 4,377
  • 2
  • 24
  • 38