iOS-UIScrollView在Xib中使用

339 阅读1分钟

WeChatb046847b4068745b43e73b26cac62bf6.jpg

XCode11之后,UIscrollVIew布局中添加了 Content Layout guide 选项,默认选中

  • 选中状态,UIscrollVIew 下出现 Content Layout Guide 和 Frame Layout Guide
  • 取消选中,Content Layout Guide 和 Frame Layout Guide 消失
  • So,有两种使用方式

使用1:不选中 Content Layout Guide

  • 1.创建ScrollView,并设置约束
    • 先不用管报错

WeChatcd6456d6b1aee90a0fbe6dcc3c7ee753.jpg

  • 2.在ScrollView下 ,添加一个内容视图 View ,设置上下左右约束
    • 如果让 内容视图 View 上下滚动,需设置约束 Horizontally in container
    • 如果让 内容视图 View 上下滚动,需设置约束 Vertically in container
    • 如果 内容视图 View 宽或高是固定的,直接设置即可,以下是上下滑动时根据内容视图的高度适配滚动

WeChatd6ad02118d449b0fca0839a3f3598374.jpg

  • 3.给内容视图View设置 intrinsic size 【消除报错】【width、height 可自行修改,不会影响使用】

WeChat8106a7ba36456cf48a1df87ca0669dce.jpg

  • 4.在内容视图View下添加要展示的内容,用一个UIlabel演示,设置上下左右约束

WeChatdfbea401486032a7eb927934e1c06abf.jpg

  • 5.修改UILabel内容,直接查看效果

屏幕.gif

使用2:选中 Content Layout Guide