Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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