Make UIView fill containing view using auto layout

2019-01-24 02:23发布

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.

2条回答
可以哭但决不认输i
2楼-- · 2019-01-24 02:56

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

查看更多
欢心
3楼-- · 2019-01-24 02:58

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

查看更多
登录 后发表回答