When implementing the design of a view controller, one of the most important steps is correctly placing your views on your screen. The way to achieve that is constraints. There are two kinds of constraints in Kodika. The Pin Constraints  and the Advanced Constraints . In this article, we will explain how the Pin Constraints  work, and how to use them.

Pin constraints , as indicated by their name, "pin" a certain aspect of the view, with one constant. It is important to note, that all pin constraints' constants, but height's and width's, are in reference with its superview. Let's add a view, to better understand Pin Constraints.

We notice that there are four default Pin Constraints  add to it. A pin constraint regarding the placement of the top edge of the view, one for the left edge, and two regarding its width and height. The means that no matter the size of the screen, this view will always keep a distance of 10 points from the top of the screen and 10 points from the left. Also, its width and height will stay fixed at 85*85 no matter what.

If we try adding a right pin constraint to the view, this error message will pop up.

This error is expected because there is no way for a view to have set both left and right edges, and a fixed width, due to the difference of the screen sizes in iPhone devices. The same error will be shown if we try to add the pin constraint to the bottom edge of the view.

Some examples of pin constraint combinations!
 

In which views should you use Pin Constraints? When not wanting to implement a demanding design, but simply want to add a view to its superview, with some standard dimensions. 

Did this answer your question?