Suggested Constraints

The course is part of this learning path

Start course
1h 1m

In this course focused on layouts, we're going to see how to create user interfaces for our apps so that you can see how views work and you'll learn how to create views just using code rather than your main storyboard.

Intended Audience

This course is designed for anyone who wants to:

  • Learn about iOS development and coding
  • Move into a career as an iOS developer
  • Master Swift skills


To get the most out of this course, you should have some basic knowledge of iOS.


Hi, within these lectures, we're going to see a way to implement these constraints in a very easy way. So far, we have been doing these constraints in a manual way. So, if you choose the view, if you choose your phone from here and click on the third option over here, you will see some menus. So, we have worked with this before. So, if you choose one of the views, the upper side will just work on that view and the below side, the bottom side will work on all of these views.

So, if you see Clear Constraints here, if you click on that button, it will clear all the constraints. It will delete all the constraints in your app as you can see. Now, I clicked it and all the constraints that we have been worked on so far have been erased. Now, I'm going to go and do this automatically rather than manually. So, you can try to choose every view or you can just click on here and come over this option one more time. You will see Add Missing Constraints and Reset to Suggested Constraints. For right now, I'm going to go for Reset to Suggested Constraints. If I do that, this will add the constraints itself.

So, this is pretty much what we have done in the previous lectures, it's kind of different but it's adding some constraints to Image View and it's adding some constraints to label as well. So, after you do this, after you Reset to Suggested Constraints, you can try to run this on iPhone SE or iPhone XR, and try to see how does it look like on your phone. So, if you're satisfied with this view then it's okay, you can go for it, and if you're not satisfied at this point, you may have to Clear Constraints or you may have to go these constraints one by one and try to adjust them in your own way. So, in the apps that we're going to be building, we're just going to use this app to suggested constraints generally. So, let me change this to Scale To Fill or Aspect Fit and try like this. So, if I'm satisfied with this look that I get, then I don't have to change anything else. And again, if I'm not satisfied, I'm going to have to start from the beginning.

For example, let me clear these constraints one more time and let me add some manual constraints to my Image View on the second option over here. So, let me choose the left, right, and the top constraints and add these three constraints. As you can see, there are still some missing constraints that I need to add in order this to work and I have these red lines stating that there is a problem with the layout. Then I can go over here, turn the option, and I can say Add Missing Constraints. So, after I specifically choose, after I specify what I want to specify, I can leave the rest to Xcode as well. I can just say, ''Okay, I have done my thing." Now add the missing constraints and it will give me the same result.

So, this is how you work with layout. This is how you try to make your app work exactly the same in different kinds of screen sizes or iPhone models. And of course, depending on your complexity, you may have to spend more time working on this manual constraints or automatic constraints. After this section, we will be focusing on the coding side rather than this layout side. So, we will be using Reset to Suggested Constraints a lot, but I'm going to show you some other ways to create views. For example, not with using the Main.storyboard, but just using codes. And then, we will be ready to move on. Let's do that in the next lecture.

About the Author
Learning Paths

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics