Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Layout Basics

Constraints

When we created the View frame, we gave it a width of 200. Why did this not suffice? Why did we also have to change the width to 200 within the Add New Constraints menu?

1 Answer

You will receive a warning stating that position and size of view are ambiguous if you do not. Xcode won't be able to discern the exact size you want it and x,y coordinate it should be at. If you use constraints you must provide all of the necessary constraints so that the device can discern exactly what you want.

Also when you are adding constraints sometimes you want the object to keep a certain width or height no matter what screen size it appears on.

Lets say you have a pop up custom view and it needs to have a height of 100 and width of 200 so that it keeps the same look no matter what screen size. If the views width became shorter the text could become too small or not all words could be shown. For instance Apple requires apps to use a minimum of 11pt font.

Thank you!