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 Introduction to Auto Layout in iOS Auto Layout in Code NSLayoutConstraint

Mert Kahraman
Mert Kahraman
12,118 Points

Minus or positive issue is unclear

Pasan first mentions we must add the constraint of a -50.0. (and that code magically appears on the video)

But then he makes it a positive 50.0 and it works fine.

Then why mention it has to be -50.0?

2 Answers

Roger Antonell
Roger Antonell
18,252 Points

It all depends the constraint equation that you apply.

if you apply: label.trailing = superview.trailling margin - 100 then the constant have to be -100, if you apply: superview.trailling margin = label.trailing + 100 then the constant have to be +100

to test it you can select a constraint in the "Document outline" and in the "size inspector" go to first item and select the option "Reverse First and second Item", once you did you will have to change the +100 to a -100

Bertram Srugies
Bertram Srugies
4,704 Points

Thank you for this explanation, made it very clear for me.

Florian Thompson
PLUS
Florian Thompson
Courses Plus Student 18,609 Points

Could it be he was talking about a -50 offset but was using a 50 inset?