如何在xib中描述一个scrollView的步骤:
(Xcode10以后记得勾选掉Content Layout Guides,如果看官有更好的办法,希望告知下,感激不尽)

1.拖入一个scrollView并设置他的frame
2.将一个UIView拖入scrollView,成为scrollView唯一的子控件,并设置UIView相对scrollView上下左右对齐(即用UiView完全填充Scrollview)
3.设置UIView宽度和高度,即为scrollView的contentSize
4.设置UIView水平对齐,即为scrollView垂直滚动,设置UIView垂直对齐,即为scrollView水平滚动
5.要设置scrollView的contentSize随子控件而改变,则删除UIView的高度,并设置最底部的子控件UIView距离为XXX
在storyboard\xib中给UIScrollView子控件添加约束
- 给添加一个UIView类型的子控件A(这将是UIScrollView唯一的一个子控件)
- 设置A距离UIScrollView上下左右间距都为0
- 往A中再添加其他子控件

- 上下滚动(垂直滚动)
- 设置A的高度(这个高度就是UIScrollView的内容高度: contentSize.height)

- 设置A在UIScrollView中左右居中(水平居中)

- 左右滚动(水平滚动)
- 设置A的宽度(这个宽度就是UIScrollView的内容宽度: contentSize.width)

- 设置A在UIScrollView中上下居中(垂直居中)

- 上下左右滚动(水平垂直滚动)
- 设置A的宽度(这个宽度就是UIScrollView的内容宽度: contentSize.width)
- 设置A的高度(这个高度就是UIScrollView的内容高度: contentSize.height)


网友评论