Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UIView fill containing view using auto layout in Interface Builder instead of code

How do I use auto-layout to make a child view fill its parent, or at least anchor all its edges to the parent view's edges?

I am using all four vertical and horizontal constraints in "Spacing to nearest neighbour", but when I run the app on a 3.5" device, the height of the view has not been automatically adjusted from 568 to 480 as expected.

like image 627
Steve Avatar asked May 24 '14 16:05

Steve


People also ask

What are two properties that auto layout constraints control on a Uiview?

Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property. The layoutMargins property lets you get and set the margins as a UIEdgeInsets structure.

How does a view's intrinsic content size aid in auto layout?

In general, the intrinsic content size simplifies the layout, reducing the number of constraints you need. However, using the intrinsic content size often requires setting the view's content-hugging and compression-resistance (CHCR) priorities, which can add additional complications.


2 Answers

Pin the top space to superview, bottom space to superview, leading space to superview and trailing space to superview.

Pin

Then set edit the constraints like so:

Superview.Top >= View.Top and Superview.Bottom >= View.Bottom

like image 158
67cherries Avatar answered Sep 30 '22 19:09

67cherries


I would just set all "Spacing to nearest neighbor" to 0, and align horizontal and vertical center. That should do the trick.

like image 36
Anfaje Avatar answered Sep 30 '22 20:09

Anfaje