4

I have a UIStackView inside a UIScrollView, and when the width of all items in stack view is less then the width of the scroll view, I want to make the stack view (or the items) to be horizontally centered aligned with the scroll view.

I have the following constraints:

For scrollView: H:|[stackView]| and V:|[stackView]| (so stack view fits with scroll view)

But I can see the stack view seems to shrink to a minimum size that just enough for all its arranged subviews' intrinsic content size, and it's left aligned to the scroll view.

Is there anyway to make it horizontally-centred in the scroll view?

Thanks!

Heuristic
  • 5,087
  • 9
  • 54
  • 94

1 Answers1

4

take a look at this: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/LayoutUsingStackViews.html search for 'Dynamic Stack View', it worked for me

gutte
  • 1,373
  • 2
  • 19
  • 31