Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding "firstBaseLine" vs. "baseLine" AutoLayout Constraint

Tags:

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.

like image 952
softshipper Avatar asked Mar 23 '16 20:03

softshipper


People also ask

What is Autolayout when and where would you use it?

What is Auto Layout? Auto Layout is a constraint-based layout system designed for building dynamically sized user interfaces. It lets you create user interface layouts that dynamically adapt for all screen sizes without manually setting the frame of every view.

What is baseline in iOS?

firstBaseLine refers to the top baseline of a multi-line object: Storyboard warning : First baseline layout attribute before iOS 8.0. if the label or text field involved only has one line, it's a useless constraint.

What is baseline in xcode?

Swift version: 5.6. All performance tests in Xcode can have baselines attached to them, which are stored results that you consider representative of your app's performance as things stand.

Why do we use Autolayout?

When making responsive designs: Auto Layout is essential for making responsive designs, since it allows you to easily change the size and position of elements based on the screen size. This can save you a lot of time and effort when compared to having to create separate designs for different screen sizes.


1 Answers

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

like image 175
naomimichiko Avatar answered Sep 22 '22 13:09

naomimichiko