Adding Auto Layout to the Restaurant cell  

Since we have many elements in the Restaurant cell, it means that there are more chances for errors with Auto Layout. Although you may be frustrated at times using Auto Layout, if you are a visual person like me, hopefully you will eventually appreciate using it:

  1. Select the top label and then enter the following values:
  1. Click Add 4 Constraints.
  2. Now, select the Label right below the last label, then, the Pin icon. Enter the following values:
  1. Click Add 4 Constraints.
  2. Next, select the Image container and, then, the Pin icon. Enter the following values:
  1. Click Add 3 Constraints.
  2. Next, click on the Align icon and enter the value of Horizontally in Container as 0 (this should be checked).
  1. Click Add 1 Constraint.
  2. Now, select the Image inside of the container and, then, the Pin icon. Enter the following values:
  1. Click Add 4 Constraints.

 

  1. Now, select the container that is holding the stack view and the available time's label and, then, the Pin icon. Enter the following values:
  1. Click Add 3 Constraints.
  2. Next, click on the Align icon and enter the value Horizontally in Container as 0 (this should be checked).
  1. Click Add 1 Constraint.
  2. Now, select the stack view inside of the container and, then, the Pin icon. Enter the following values:
  1. Click Add 4 Constraints.
  2. Next, select the Label above the three buttons and, then, the Pin icon. Enter the following values:
  1. Click Add 4 Constraints.
  2. Finally, click on the Align icon and enter the value of Horizontally in Container as 0 (this should be checked).
  1. Click Add 1 Constraint.

Now, all of the Auto Layout for the Restaurant cell is set up. Let's build and run our project and go to the restaurant cell. Everything should look like the design we reviewed earlier in the book.