Skip to content

Commit

Permalink
Complete Challenge 3
Browse files Browse the repository at this point in the history
> Try making the height of your labels equal to 1/5th of the main view, minus 10 for the spacing.
  • Loading branch information
CypherPoet authored and CypherPoet committed Mar 8, 2019
1 parent 937ee13 commit 1d30fef
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions day-030/projects/Auto Layout/Auto Layout/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,20 @@ class HomeViewController: UIViewController {
label.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
label.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true

label.heightAnchor.constraint(equalToConstant: 88).isActive = true
label.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, multiplier: 0.2, constant: -10).isActive = true

if labelNumber > 1 {
let labelAbove = labels["label\(labelNumber - 1)"]!

// create a topAnchor constraint if we have a previous label (and thus, a bottomAnchor to offset from)
/// create a topAnchor constraint if we have a label above us (and thus, a bottomAnchor to offset from)
label.topAnchor.constraint(equalTo: labelAbove.bottomAnchor, constant: 10).isActive = true

if labelNumber == labels.count {
/// anchor the last label against the bottom `safeAreaLayoutGuide`
label.bottomAnchor.constraint(greaterThanOrEqualTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 10).isActive = true
}
} else {
label.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
label.topAnchor.constraint(greaterThanOrEqualTo: view.safeAreaLayoutGuide.topAnchor, constant: 10).isActive = true
}
}
}
Expand Down

0 comments on commit 1d30fef

Please sign in to comment.