iOS中具有主视图的比例宽度和高度 [英] Proportional width and height with main view in iOS

查看:175
本文介绍了iOS中具有主视图的比例宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要使应用程序与所有大小的设备兼容,有时需要将 UIControl 的宽度或高度与主视图(<$ c $)成比例c> self.view 。

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.

因此,我们通常在情节提要中分配约束,将主视图的高度/宽度设置为相等,然后设置乘数。像0.3一样,它将为我设置所有控件的高度(iPhone 5s-> 568 ==> 568 * 0.3 = 170.4),依此类推。

So we used to assign constraint in storyboard, equal height/width to main view and then we set multiplier. 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.

但是正确现在,我正在使用 Xcode 11.0 创建应用。因为不能将主视图的高度或宽度设置为相等。

But right now I am creating app in Xcode 11.0. In that I cannot set equal height or width to main view.



  1. 我尝试通过选择视图和右键单击并拖动到超级视图,但没有任何选择。




  1. 然后我尝试了多项选择。选择我的视图和超级视图,然后尝试从右下角设置约束,但是没有运气。


推荐答案

直到此问题在更新中得到解决(大概是):

Until this is fixed in an update (presumably):


  • 按住Ctrl键从UIControl拖动到安全区域

  • 选择相等宽度
  • 选择新创建的约束

  • 在大小检查器窗格中,将第二项从 $code>安全区域。宽度 Superview.Width

  • Ctrl-Drag from your UIControl to "Safe Area"
  • Select "Equal Widths"
  • Select the newly created constraint
  • In the Size Inspector pane, change Second Item from Safe Area.Width to Superview.Width

尽管...您可能会更好离开它放在安全区域

Although... you are probably better off leaving it at Safe Area

这篇关于iOS中具有主视图的比例宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆