Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Simple iPhone App with Objective-C Improving Our User Interface Implementing Auto Layout

Bekzod Rakhmatov
Bekzod Rakhmatov
7,419 Points

Auto Layout In Objective-C Can Somebody explain it?

1) I was following the constructor but he suddenly change the screen and the sizes did change but he did not say anything about it? It was happening when it was 4:20 s his left margin was 48 and right was 47 but then he clicked 2nd icon and boom these were changed but how they were 32 and 31 ? 2) When I vertical centered it went down to center but on video it was just where it was

1 Answer

Michael Hulet
Michael Hulet
47,893 Points

This has to do with the checkbox that he mentions labeled "Constrain to margins". With Interface Builder, you need to select if you want the constraints you set to be relative to the margins that iOS sets or if you want it set to the edges of the screen. iOS automatically selects margins for you to make sure that elements never get pushed up against the edge of screen and look weird, but that isn't always what you want. The default that is set when you bring up that constraints view in Interface Builder is to add constraints relative to the margins, which are closer to the content than the edges of the screen. Thus, the numbers representing the distance of the constraint will be smaller than if the box was unchecked. If you'll notice, Pasan unchecked this box a few seconds earlier in the video, but that checkbox resets every time you open that popover, so even though the numbers were bigger when he closed it at first, they were smaller again when he opened it the next time