参考链接: https://www.jianshu.com/p/879f734f3479
一、添加scrollview
拖入scrollview ,去掉右边栏Content Layout Guides,设置上下左右约束为0
二、拖入UIView到scrollview下,改名为contentview
三、设置contentview相对于scrollview的约束(选中contentview,右键拖线到scrollview),设置上下左右约束都为0及居中约束(这里有一个细节,如果你的scrollview是上下滑动,则居中约束设置为Center Horizontally in Container,如果是左右滑动则居中约束设置为Center Vertically in Container,如果左右上下都要滑动则不需要设置。本文以上下滑动为例子,即设置Center Horizontally in Container约束)如图
注意:接下来就是布局你的视图了,到目前为止还会出现红色警告。
#四、拖入你想要布局的view到contentview下,这里以两个view为例子,重点注意:最后一个view要设置Bottom Space to Container约束。