首页 文章

仅在界面构建器中使用AutoLayout在UIScrollView中居中UIView

提问于
浏览
2

我正在尝试仅使用界面构建器将视图置于UIScrollView中 . 随着标签似乎运作良好 .

enter image description here

enter image description here

但是当我尝试用UIView做同样的事情时,我遇到了约束冲突 .

enter image description here

enter image description here

enter image description here

冲突是有道理的,但是如果我删除宽度/高度约束,UIView会扩展到整个SuperView,如果我删除top / lead / trail / bottom约束,UIView会正确居中,但是我得到一个模糊的宽度/高度警告 .

enter image description here

我的问题是,我怎样才能让UIView的中心与UILabel相同?

2 回答

  • 1

    备查:

    enter image description here

    enter image description here

    但关键是要设置不同的ContentHugging优先级,以帮助AutoLayout解决冲突:

    enter image description here

  • -1

    这很简单,基本上你所要做的就是: -

    为对象提供高度和宽度常量

    enter image description here

    然后添加这些contstans: -

    • 在容器中水平

    • 在容器中垂直

    enter image description here

相关问题