ios 使用界面生成器中的自动布局而不是代码使 UIView 填充包含视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23847259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:12:31  来源:igfitidea点击:

Make UIView fill containing view using auto layout in Interface Builder instead of code

iosobjective-cxcodeinterface-builderautolayout

提问by Distortum

How do I use auto-layout to make a child view fill its parent, or at least anchor all its edges to the parent view's edges?

如何使用自动布局使子视图填充其父视图,或者至少将其所有边缘锚定到父视图的边缘?

I am using all four vertical and horizontal constraints in "Spacing to nearest neighbour", but when I run the app on a 3.5" device, the height of the view has not been automatically adjusted from 568 to 480 as expected.

我在“与最近邻居的间距”中使用了所有四个垂直和水平约束,但是当我在 3.5" 设备上运行该应用程序时,视图的高度没有按预期从 568 自动调整到 480。

回答by 67cherries

Pin the top space to superview, bottom space to superview, leading space to superview and trailing space to superview.

将顶部空间固定到超级视图,底部空间固定到超级视图,引导空间到超级视图,尾随空间固定到超级视图。

Pin

别针

Then set edit the constraints like so:

然后像这样设置编辑约束:

Superview.Top >= View.Topand Superview.Bottom >= View.Bottom

Superview.Top >= View.TopSuperview.Bottom >= View.Bottom

回答by Anfaje

I would just set all "Spacing to nearest neighbor" to 0, and align horizontal and vertical center. That should do the trick.

我只是将所有“与最近邻居的间距”设置为 0,并对齐水平和垂直中心。这应该够了吧。