Proportional width and height with main view in iOS

不打扰是莪最后的温柔 提交于 2020-01-25 03:59:07

问题


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.

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.

But right now I am creating app in 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.


回答1:


Until this is fixed in an update (presumably):

  • 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



来源:https://stackoverflow.com/questions/58466866/proportional-width-and-height-with-main-view-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!