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

时间:2016-07-21 18:52:26

标签: xcode uiview uiscrollview autolayout interface-builder

我试图仅使用界面构建器将视图置于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相同?。

1 个答案:

答案 0 :(得分:1)

供将来参考:

enter image description here enter image description here

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

enter image description here