I have a view hierarchy on iOS arranged like this:
UIViewController
- UIView
- UIButton
- UIButton
- UIScrollView
- UIStackView
- UILabel
- UIDatePicker
- UILabel
- UIDatePicker
The scroll view is pinned to 20 from leading and trailing space on the superview, 0 from the bottom of one of the buttons, and 0 to the bottom layout guide.
The stack view has 0 leading, trailing, top, and bottom space to the superview (the scroll view).
I like how this looks in vertical orientation:
But in horizontal orientation, I think the long lines extending beyond the main content of the UIDatePicker
are kinda ugly:
I've tried many permutations of constraints (max width + center X on the UIDatePicker
s, increasing various content hugging priorities, no width constraints on the UIScrollView
and center X on it), but all have resulted in ambiguous layouts or conflicting constraints. How can I do what I'm aiming for here?
EDIT: With the constraints as suggested below (ScrollView pinned to container, StackView pinned with 0 Trailing, Leading, Bottom, and Top space to the ScrollView, and a width equal constraint on the date pickers) the StackView refuses to expand its width and stays pinned to the left of its parent.
This happens even though there are leading and trailing constraints set to 0 on the StackView.
UIDatePicker
extending to the edge of the screen makes it quite difficult to scroll. – Scott Colby