首页 > 解决方案 > Xcode 故事板:如何使用 10 多个文本字段适应不同的屏幕尺寸

问题描述

我已经在差不多 +2 天内一直在使用布局。观看多个 youtube 视频,阅读几乎 50 多个堆栈溢出线程,但我无法让我的布局适应不同的屏幕尺寸。

我在另一个视图中有一个视图。所以主视图是全屏,子视图是半屏。问题是即使我设置了约束和所有这些,它也不会自动适应不同的大小,尤其是标签/文本字段。

关于如何解决这个问题的任何想法?

标签: iosswiftlayoutautolayoutconstraints

解决方案


So if I understood correctly you want the second View to be always the half of the main View.Because the main is the whole screen and its going to be half the screen.

If you want something like this

enter image description here

Go to your storyboard

  • Add the secondView.
  • Add equal height with the main View(ctrl drag to main view).
  • 0 from right and top.
  • Then make the width half of the main view.(Multiplier: 0.5) enter image description here enter image description here

推荐阅读