中心UI视图中的元素与自动布局 [英] Center UI elements in view with autolayout
本文介绍了中心UI视图中的元素与自动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用自动布局做一个UI元素居中左到右的风景和肖像模式下?你可以有变量自动布局?
How do you use Autolayout to make a UI Element centered left-to-right when in both landscape and portrait mode? Can you have variables in autolayout?
推荐答案
如果您正在使用接口生成器来创建和放大器;设置视图的位置,选择查看&放大器;作为做下面的截图显示。
If you are using Interface builder to create & set position of your view, Select your View & do as the screenshot suggests below.
之后,点击添加约束&放大器;你做。这仅仅是设置在水平中心的视图。但是你必须还添加一些更多的约束。它们是:
After that, click on "Add constraint" & you are done. This is just to set your view in horizontal centre. But you have to still add some more constraints. They are:
- 高度
- 宽度
- 从顶部/底部布局指南/视图的距离。
让我知道,如果你不知道如何做到这一点。
Let me know if you don't know how to do this.
这篇关于中心UI视图中的元素与自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文