简体   繁体   English

iOS中主视图比例宽高

[英]Proportional width and height with main view in iOS

To make application compatible with all sizes of devices, At some point we need to give width or height of UIControl in proportion with main view that is our self.view .为了使应用程序与所有尺寸的设备兼容,在某些时候我们需要给UIControl的宽度或高度与主视图的比例,即我们的self.view

So we used to assign constraint in storyboard, equal height/width to main view and then we set multiplier.所以我们过去在 storyboard 中分配约束,与主视图相等的高度/宽度,然后我们设置乘数。 Like 0.3 So it will set height of my control (iPhone 5s --> 568 ==> 568*0.3 = 170.4) and so on for all devices.像 0.3 所以它将为所有设备设置我的控件的高度(iPhone 5s --> 568 ==> 568*0.3 = 170.4)等等。

But right now I am creating app in Xcode 11.0 .但现在我正在Xcode 11.0中创建应用程序。 In that I cannot set equal height or width to main view.因为我不能将相同的高度或宽度设置为主视图。

  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. Select 我的视图和超级视图,然后尝试从右下角设置约束,但没有运气。

在此处输入图像描述

Until this is fixed in an update (presumably):直到这在更新中得到修复(大概):

  • Ctrl-Drag from your UIControl to "Safe Area" Ctrl-Drag 从您的 UIControl 到“安全区域”
  • Select "Equal Widths" Select“等宽”
  • Select the newly created constraint Select 新创建的约束
  • In the Size Inspector pane, change Second Item from Safe Area.Width to Superview.Width在 Size Inspector 窗格中,将 Second Item 从Safe Area.WidthSuperview.Width

Although... you are probably better off leaving it at Safe Area虽然……你最好把它留在Safe Area

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

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