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 - iOS Tutorial
From the course: iOS Development: Auto Layout Programmatically
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Basic preparation3m 53s
-
(Locked)
Pin and size individual constraints7m 59s
-
(Locked)
Anchors and the safe area5m 54s
-
(Locked)
Align views9m 24s
-
(Locked)
Errors in Auto Layout8m 26s
-
Size views with multipliers5m 40s
-
(Locked)
Aspect ratio with multipliers5m 37s
-
(Locked)
Challenge: Oatmeal56s
-
(Locked)
Solution: Oatmeal7m 29s
-
(Locked)
-
-
-
-
-