Skip to content

Instantly share code, notes, and snippets.

@TerryCK
Created August 8, 2017 02:12
Show Gist options
  • Save TerryCK/8e4ce3e370d022219498032d34ad1f4e to your computer and use it in GitHub Desktop.
Save TerryCK/8e4ce3e370d022219498032d34ad1f4e to your computer and use it in GitHub Desktop.
NSLayoutConstraint.swift
let redView = UIView()
redView.backgroundColor = .red
view.addSubview(redView)
redView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
redView.topAnchor.constraint(equalTo: view.topAnchor, constant: 40),
redView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -40),
redView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 40),
redView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -100),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment