Understanding "firstBaseLine" vs. "baseLine" AutoLayout Constraint

softshipper picture softshipper · Mar 23, 2016 · Viewed 13.5k times · Source

I've created the following view that looks as follow:

screenshot 1

And used Add missing constraints t automatically add constraints. I am pretty new in iOS world and I'm trying to configure out how constraints work.

On document outline, I can see the added constraints:

screenshot 2

I click on label UR and Size inspector show me following:

screenshot 3

What is the difference between constraints aligned by first baseline to UL and aligned by baseline to UL? When I click on the size inspector on constraints button, it shows me the same line.

Answer

naomimichiko picture naomimichiko · Mar 23, 2016

From the Apple Docs:

NSLayoutAttributeBaseline
The object’s baseline.
Available in iOS 6.0 and later.
NSLayoutAttributeFirstBaseline
The object’s baseline. For objects with more than one line of text, this is the baseline for the topmost line of text.
Available in iOS 8.0 and later.

Here is also a screenshot of the difference when aligning to a three line label. The upper green label is using NSLayoutAttributeFirstBaseline and the lower green label is using NSLayoutAttributeBaseline. These are the only constraints on the two green labels besides they are both Horizontally pinned 40 from the Pink Label

DebuggingBaselineConstraints