简体   繁体   English

在启用自动布局和尺寸类别的情况下更改视图宽度

[英]Change view width with autolayout and size class enabled

我已经为iPhone5s完成了示例屏幕的设置,并在swift中启用了自动布局和尺寸类别。我在屏幕顶部有一个视图(宽度为320)。如何为iPhone6和iPhone6Plus屏幕自动增加视图宽度。提前感谢。

You don't set the width. 您没有设置宽度。 You make constraints to the left and right edges of the superview so it will always be the width of the screen (assuming that the superview is the controller's self.view). 您可以对超级视图的左右边缘进行约束,因此它将始终是屏幕的宽度(假设超级视图是控制器的self.view)。

如果您希望视图的尺寸遵循与其运行的iPhone相同的宽度,请在Interface Builder中放置视图,调整视图的大小,使其基本看起来像您想要的样子,然后添加约束,ctrl从您的视图拖动到其父视图,并添加“将空间引导到容器边距”和“将空间拖曳到容器边距”约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM