Skip to content

Instantly share code, notes, and snippets.

@muukii
Created July 10, 2021 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muukii/e3969013e5b1cde8314d73892d81b00c to your computer and use it in GitHub Desktop.
Save muukii/e3969013e5b1cde8314d73892d81b00c to your computer and use it in GitHub Desktop.
let backgroundView = UIView.mock(backgroundColor: .neon(.violet))
let box1 = UIView.mock(backgroundColor: .neon(.red), preferredSize: .largeSquare)
let box2 = UIView.mock(backgroundColor: .neon(.yellow), preferredSize: .largeSquare)
view.addSubview(backgroundView)
view.addSubview(box1)
view.addSubview(box2)
backgroundView.translatesAutoresizingMaskIntoConstraints = false
box1.translatesAutoresizingMaskIntoConstraints = false
box2.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
backgroundView.topAnchor.constraint(equalTo: view.topAnchor),
backgroundView.leftAnchor.constraint(equalTo: view.leftAnchor),
backgroundView.rightAnchor.constraint(equalTo: view.rightAnchor),
backgroundView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
box1.topAnchor.constraint(equalTo: view.topAnchor, constant: 10),
box1.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10),
box1.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10),
box2.topAnchor.constraint(equalTo: view.topAnchor, constant: 10),
box2.leftAnchor.constraint(equalTo: box1.rightAnchor, constant: 10),
box2.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10),
box2.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -10)
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment