Search code examples
iosautolayoutuistackview

Resizing a UIStackView using AutoLayout


I have the following setup in my storyboard. I want the selected UIStackView to stretch across it's parents view so its right edge is the same distance away from the edge of the screen as the left edge.

Control dragging from the stackview to it's parent view and selecting "Trailing space to container margin" doesn't do what I thought it would (I am very new to auto layout). What is the correct way to resize this stackview? TIA

enter image description here


Solution

  • Control click and drag form your stackView to it's superview. Then pick Center Horizontally. Adding a leading constraint should be sufficient.