Skip to content

Instantly share code, notes, and snippets.

@mitulmanish
Created April 8, 2018 02:26
Show Gist options
  • Save mitulmanish/daec7f62f7d14d10844f1c2da63eb6b6 to your computer and use it in GitHub Desktop.
Save mitulmanish/daec7f62f7d14d10844f1c2da63eb6b6 to your computer and use it in GitHub Desktop.
extension UIView {
func pin(toView view: UIView) {
self.translatesAutoresizingMaskIntoConstraints = false
let topConstraint = self.topAnchor.constraint(equalTo:
view.topAnchor)
let bottomConstraint = self.bottomAnchor.constraint(equalTo: view.bottomAnchor)
let leadingConstraint = self.leadingAnchor.constraint(equalTo: view.leadingAnchor)
let trailingConstraint = self.trailingAnchor.constraint(equalTo: view.trailingAnchor)
NSLayoutConstraint.activate([topConstraint,
leadingConstraint,
trailingConstraint,
bottomConstraint])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment