Created
April 8, 2018 02:26
-
-
Save mitulmanish/daec7f62f7d14d10844f1c2da63eb6b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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