Skip to content

Instantly share code, notes, and snippets.

@froggomad
Created June 18, 2021 17:41
Show Gist options
  • Save froggomad/0e95f04438bcef2a05476eba9919db41 to your computer and use it in GitHub Desktop.
Save froggomad/0e95f04438bcef2a05476eba9919db41 to your computer and use it in GitHub Desktop.
class TitledCollectionViewController: UIViewController {
lazy var fruitView = TitledCollectionView(produce: .fruit)
lazy var vegetableView = TitledCollectionView(produce: .vegetable)
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
}
func setupViews() {
view.backgroundColor = .systemBackground
view.addSubview(fruitView)
view.addSubview(vegetableView)
NSLayoutConstraint.activate([
fruitView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20),
fruitView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -20),
fruitView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
fruitView.heightAnchor.constraint(equalToConstant: TitledCollectionView.Layout.heightConstant),
vegetableView.topAnchor.constraint(equalTo: fruitView.safeAreaLayoutGuide.bottomAnchor, constant: 20),
vegetableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -20),
vegetableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
vegetableView.heightAnchor.constraint(equalToConstant: TitledCollectionView.Layout.heightConstant),
])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment