Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
On top of creating a relationship with a constraint, we can also specify how that relationship behaves. In this video, we take a look at the different relationship types and how it affects our layout

0:00
Once you've identified the kinds of attributes you want to use,

0:03
the next step is to build a relationship between the attributes.

0:07
There are three kinds of relationships we can build.

0:09
And so far in our courses, we've only used one, an equal relation.

0:14
An equal relation is very intuitive, and simply says,

0:17
I want ViewB's height attribute to equal ViewA's height attribute.

0:22
There are two more kinds of relationships we can establish between attributes,

0:26
a less than or equal and a greater than or equal.

0:31
As the title states, when you specify a less than or equal relationship,

0:36
you're saying that I want ViewB's width attribute to be less than or

0:40
equal to ViewA's width attribute by a certain amount.

0:44
We can do the opposite with the greater than or equal relation, and

0:47
these two are known as inequality constraints.

0:50
Once we've established the type of relationship we want to create,

0:54
the next part is the multiplier.

0:56
The multiplier is a fixed value that lets you adjust the relationship between

1:01
the two attributes by a certain factor.

1:03
For example, you can say that you want ViewB's height to be equal to 0.75 times,

1:08
or twothirds that of ViewA's height.

1:12
The 0.75 value here is the multiplier.

1:14
The multiplier is a required value and

1:16
often times the value provided is simply one to keep the relationships equal.

1:21
But the multiplier is really powerful because you can use

1:23
any floating point number to build that relationship.

1:27
It is important to know that the multiplier cannot be changed

1:29
after you've created the constraint equation.

1:32
If you want to modify the multiplier,

1:34
you essentially need to get rid of the constraint, and create a new one entirely.

1:39
So let's go back to the constraint equation.

1:41
We now know what attributes are available to us to use,

1:44
as well as what the multiplier does.

1:46
So the last bit remaining is the constant.

1:49
The constant is quite easy to understand and allows us to offset a view

1:53
from any desired attribute by a certain floating point value.

1:57
In our very first example, we said we wanted to position a label away from

2:01
the bottom of the superview by a certain amount of padding.

2:04
That padding is this constant value.

2:07
A second ago, we mentioned that there were three types of relationships we could set

2:11
up, equal, greater than or equal, and less than or equal.

2:15
When we implement the inequality constraints, we use the constant value to

2:19
specify the number we want to be greater than or equal to.

2:23
Funnily enough, as I mentioned earlier,

2:25
the constant in this constraint equation is not actually constant.

2:29
While the attributes and

2:30
multiplier are fixed when you create the constant, you can modify the constant bit

2:35
of the constraint at any point to adjust the offset.

2:39
Constant here implies that it is a constant offset away,

2:43
rather than a value that is unchanging.

2:45
Okay, let's use this knowledge to build up a few examples over the next few videos.
You need to sign up for Treehouse in order to download course files.
Sign up