iOS 中主视图的宽度和高度比例

Proportional width and height with main view in iOS

为了使应用程序与所有尺寸的设备兼容,在某些时候我们需要根据我们的 self.view.

主视图按比例提供 UIControl 的宽度或高度

所以我们过去常常在故事板中分配约束,等于 height/width 到主视图,然后我们设置乘数。像 0.3 所以它会为所有设备设置我的控件的高度(iPhone 5s --> 568 ==> 568*0.3 = 170.4)等等。

但现在我正在 Xcode 11.0 中创建应用程序。因为我不能为主视图设置相同的高度或宽度。

  1. I have tried by selecting my view and right click and drag to superview, but there is no any option.

  1. Then I have tried with multiple selection. Select my view and superview and then tried to set constraint from bottom right corner, but no luck.

在更新中解决此问题之前(大概):

  • Ctrl-从您的 UIControl 拖动到 "Safe Area"
  • Select "Equal Widths"
  • Select新创建的约束
  • 在尺寸检查器窗格中,将第二项从 Safe Area.Width 更改为 Superview.Width

尽管...您最好还是留在 Safe Area