Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What constraints to add to make an UIView take half the size of the screen size

Tags:

ios

autolayout

I want my UIView to take half o the screen size, so the constraints should be: 0 for top, leading and bottom. But what about trailing edge ? I do not want to set a constant value to it.

How can I tell IB that the trailing edge should adjust automatically so that the view is half of the screen on all devices ?

like image 517
Adrian Avatar asked Jul 26 '15 08:07

Adrian


People also ask

How to add constraints in Uikit?

You can also create multiple constraints at once, or you can update the frames as you add the constraints. After you've set the options you want, click the Add Constraints button to create your constraints.

How to add constraints to view in Xcode?

To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button. Run the application.

What are constraints in swift?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.


1 Answers

I fixed my problem by ctrl dragging from my view to its superview and choose Equal Widths and then selected the new constraint and in the Size Inspector under Multiplier I changed from 1 to 1:2.

like image 87
Adrian Avatar answered Nov 15 '22 06:11

Adrian