问题
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.
- I have tried by selecting my view and right click and drag to superview, but there is no any option.
- 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
toSuperview.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