I want to make a child view stretch to its parent view full size. What is the correct way to use auto layout?
- Pin all edges to parent view (leading, top, trailing, bottom edges)
- Set equal-width + center-X + equal-height + center-Y
I want to make a child view stretch to its parent view full size. What is the correct way to use auto layout?
Both the options you suggest will do the job ( first 1 is the common ) in addition
1- top ,leading ,equal width and height
2- bottom ,trailing,equal width and height
3- top ,leading ,trailing and equal height
4- top , bottom ,leading,equal width
also there are many ways to do this , there is no set correct over the other the most important thing is having non-breaking constraints as if conflicts occured there will be performance problems in addition to unexpected UI results
As I see it, option 1 is the only way to go. Both options will do the trick, but I strongly believe that 1 is way more "correct" than option 2.
Auto layout is a language, and as such we should use its grammar correctly. As in language, there are multiple ways to deliver a message, but some are better than others.
In this case, option 1 describes exactly what we want to do, and describes it literally: pin all of the child edges to its parent edges. Option 2, is an abuse of an edge case of centering a view, where its size is the same as another view. If we would instruct verbally our code, this is not what we would say.