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
MOD
Michael Hulet
Treehouse Moderator 47,709 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