From the course: iOS Development: Auto Layout Programmatically

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Pin and size individual constraints

Pin and size individual constraints - iOS Tutorial

From the course: iOS Development: Auto Layout Programmatically

Start my 1-month free trial

Pin and size individual constraints

- [Instructor] You've turned off the automatic mode for making constraints and it's time to start adding your own. You'll start with pins and then work with the lines and sizes. For pins, I'll make the image a background, and place the label 40 points from the top leading space. You'll add a constraint using the init method of NSLayoutConstraint. Since we needed an array, you'll make it an element of an array, then add as the array. To pin the image view to the top, for example, let's do this. Go to your imageview.layout where it says transalatesAutoresizingMaskIntoConstraints = false, give yourself some space, and right under there, type in constraints += and then []. Inside the brackets, add the constraint using NSLayoutConstraint.init. And you'll see there's two versions of this. One has a whole bunch of parameters and one has none. You need the one with all the parameters there. And you'll see that it's a bit of a monster. But it's actually not too bad, especially if you put that…

Contents