在开发中经常使用UIScrollView展示信息,为了快速开发,我们经常使用
XIB
或者Storyboard
.在最近的开发中就使用到了,并且也遇到了一些困难,查找资料之后终于成功了,为了能够帮助其他人.所有整理着这片资料供大家参考.
第一步:拖入一个UIScrollView
,可能会报错,需要把content Layout Guides
取消掉,然后设置UIScrollView相对于父视图四周的约束

第二步: 设置好UIScrollView
的四周约束之后,再设置其滚动方向(Horizontally in Container
是竖直方法; Vertically in Container
是水平方向)

第三步: 拖入一个UIView
,作为UIScrollView
的内容视图,并且名字为contentView
(名字可以根据自己喜好取).并设置contentView
相对于UIScrollView
四周的约束为0
,然后再点击设置contentView
暂时的高度.

第四步:再设置contentView
的滚动方向(Horizontally in Container
是竖直方法; Vertically in Container
是水平方向)

第五步: 根据自己需要拖入控件.这里拖入两个UILabel
作为演示.其中:一定要设置最下面控件距离contentView
底部的约束.然后再设置最下面控件的高度.

第六步:设置最后一个控件的高度让其>=

第七步:设置contentView
高度让其>=

这样就实现了用XIB
或 Storyboard
实现UIScrollView. 如果有什么不明白的地方,欢迎留言.
网友评论