Created
September 15, 2019 01:11
-
-
Save OscarApeland/d4a707bd56fd804ec2f86aa4feeef554 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 edgeConstraints(to view: UIView, insets: UIEdgeInsets = .zero) -> [NSLayoutConstraint] { | |
return [ | |
topAnchor.constraint(equalTo: view.topAnchor, constant: insets.top), | |
leftAnchor.constraint(equalTo: view.leftAnchor, constant: insets.left), | |
rightAnchor.constraint(equalTo: view.rightAnchor, constant: -insets.right), | |
bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -insets.bottom) | |
] | |
} | |
func edgeConstraints(to guide: UILayoutGuide, insets: UIEdgeInsets = .zero) -> [NSLayoutConstraint] { | |
return [ | |
topAnchor.constraint(equalTo: guide.topAnchor, constant: insets.top), | |
leftAnchor.constraint(equalTo: guide.leftAnchor, constant: insets.left), | |
rightAnchor.constraint(equalTo: guide.rightAnchor, constant: -insets.right), | |
bottomAnchor.constraint(equalTo: guide.bottomAnchor, constant: -insets.bottom) | |
] | |
} | |
func sizeConstraints(to view: UIView) -> [NSLayoutConstraint] { | |
return [ | |
view.widthAnchor.constraint(equalTo: view.widthAnchor), | |
view.heightAnchor.constraint(equalTo: view.heightAnchor) | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment