简体   繁体   中英

UIStoryBoard Auto Layout embed UIStackView inside UIScrollView

I'm having a problem design my ViewController which contain a some Label and a ImageView. I have embed them in a StackView. My objective is to place a StackView inside a ScrollView so that my content will be scrollable if the content is longer then the screen height

So basically what I have done is

1 - Place a UIScrollView in a scene. Pin the scroll view to its superview without margins.

2 - Place a UIStackView inside the scroll view. Pin all sides of the stack view to the scroll view without margins (yes this is counterintuitive).

3 - Vertical scrolling: Add an equal widths constraint between the scroll view and the stack view

Here is my setting in storyboard

在此处输入图片说明

But I'm getting this red warning constrains. Anyone know how to fix this? Maythanks

在此处输入图片说明

Try example given at this Link It is using following steps

  1. Create a UIScrollView, and set its constraints.
  2. Add a UIStackView to the UIScrollView
  3. Set the constraints: Leading, Trailing, Top & Bottom should be equal to the ones from UIScrollView
  4. Set up an equal Width constraint between the UIStackView and UIScrollView.
  5. Set Axis = Vertical, Alignment = Fill, Distribution = Equal Spacing, and Spacing = 0 on the UIStackView

    https://github.com/ar-juan/uistackview-in-uiscrollview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM