iOS - 更好的方式设置两个子视图的约束 [英] iOS - Better Way Of Setting The Constraint Of Two Subviews

查看:576
本文介绍了iOS - 更好的方式设置两个子视图的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图控制器中有两个子视图。我想让两个子视图在主视图内水平居中,一个位于另一个之上,并且相对于主视图具有相同的前导空格和尾随空格。



<我可以做的一个方法是设置顶部子视图相对于主视图的前导空格和尾随空格,并且在主视图中水平居中。之后,将底部子视图的前导,尾随和中心与顶部子视图对齐。





另一种方式是相对于主视图独立设置两个子视图的前导空格,尾部空格和中心





我没有两种方式的区别。因为对我来说,两者似乎有完全相同的效果。



哪种更好,更推荐?



谢谢!

解决方案

像您没有为子视图赋予高度限制,如果是这样,请根据您的要求进行以下操作:



这两个子视图的高度约束。

其他子视图的顶部子视图和顶部/底部空间边界约束的高度约束。


I have two subviews in a view controller. I want the two subviews to be centered horizontally inside the main view, one on top of the other and also having the same leading space and trailing space with respect to the main view.

One way I can do is to set the leading space and trailing space of the top subview with respect to the main view and also centering horizontally in the main view. After that, align the leading, trailing and center of the bottom subview with the top subview.

The other way is to set the leading space, trailing space, and center of the two subviews independently with respect to the main view

I don't what is the difference between the two ways. Because for me, the two seems to have exactly the same effect.

Which is better and more recommended?

Thanks!

解决方案

Both ways are equally good.Though looks like you are not giving height constraints for subviews, if this is the case then please do following based on your requirement :

Height constraint for both subviews. Or Height constraint for top subview and top / bottom space margin constraints for the other subview.

这篇关于iOS - 更好的方式设置两个子视图的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆