As you get more experience with constraints, you will come to realize that orange constraints mean !success! An orange constraint just means that the current position of the label is different than the position determined by the constraints. In a storyboard, Xcode does not automatically move the label into the position determined by the constraints. For instance, suppose you have a single label in the middle of a window, and you constrain the top of the label to be 10 from the top of the window, and you constrain the left of the label to be 5 from the left of the window. Those two constraints perfectly determine the position of the label–but the label will remain in the middle of the window, and the constraints will be orange because you have not told Xcode to move the label into the position determined by the constraints. That is a convenience for you.
The orange constraints mean that you have added enough constraints to perfectly determine the position of the label, but that you have not yet told Xcode to move the label into the position determined by the constraints–therefore at runtime when the app uses the constraints to position the label, the label will be in a different position than that shown in the storyboard. At run time, the storyboard doesn’t exist–all that exists are the constraints. In order to turn the orange constraints into blue constraints, all you have to do is Update Frames, which will instruct Xcode to move the label into the position determined by the constraints.
Another example: you move a label to the guide line indicating the center of the window. Then you constrain the center of the label to the center of the window. Next, you constrain the top of the label 50 from the top of the window. Those two constraints perfectly determine the position of the label–but the center constraint is orange. Why? It’s not easy to move a label and release it so that it exactly lines up with one of the guide lines. Often, you will be off by one pixel, which means the label needs to be moved by 1 pixel to be in the position determined by the centerX constraint, hence the orange constraint. An orange constraint will indicate how many pixels the actual position of the label is from the position determined by the constraint.
The idea is not to have move the labels into their pixel perfect positions and then try to come up with constraints to anchor them there. Rather, you only have to get things into their approximate positions, then pick the constraints you want, then click on Update Frames to move everything into their pixel perfect positions.
Well, if you say x = 2, and then you say y = x, how is it that y knows its value is 2? It’s the same principle with constraints. If you constrain the “212” label so that it is horizontally centered with relation to the window, and then you constrain the “degrees Fahrenheit” label so that its horizontal center lines up with the “212” label’s horizontal center, then the “degrees Fahrenheit” label will be centered in the window as well.
They both prevail. If they are different and they are in conflict, e.g. one constraint says the label should be 10 from the top and the other constraint says the label should be 20 from the top, then you will get red constraints. Xcode does not arbitrarily ignore one of your constraints.
Huh? If you align the horizontal centers of two labels, then their .centerX’s will be equal.
I don’t understand what that means, but one thing I always forget is that you are always lining things up with the “nearest neighbor”. For instance, if I select a Label and in the Pin menu, and I select the top bar, and I set it to 10, I always think to myself, "I’m pinning the label 10 from the top of the window–but that’s incorrect. What you are really are doing is pinning the label 10 from the nearest neighbor–that may be the top of the window, or it may be something else, like a button or a text field.
One reason you might constrain a group of labels to each other, then constrain the top label to the window is so that the group moves as a whole: if you constrain the top label to a different horizontal position, then the other labels will move with it. But there’s nothing preventing you from constraining each label independently, so that they won’t move as a group.
Edit: I think I understand what you mean now. The situation: you have three labels lined up vertically, and you want to constrain the middle label to the center of the window, then you want to constrain the other labels’ centerX to the middle labels centerX. Can you do that? The best way to find out is to start a new project, drag three labels onto the storyboard, give them the text:
and have at it. Post your results.