VRAwesome
VRAwesome

Reputation: 4803

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.

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.

enter image description here

  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.

enter image description here

Upvotes: 3

Views: 2336

Answers (1)

DonMag
DonMag

Reputation: 77540

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

Upvotes: 4

Related Questions