Created
February 12, 2020 09:49
-
-
Save vinczebalazs/ec4cb15ef89357d5efea400896c4f36a 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
func constrainToEdges(of view: UIView) { | |
translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
leftAnchor.constraint(equalTo: view.leftAnchor), | |
topAnchor.constraint(equalTo: view.topAnchor), | |
rightAnchor.constraint(equalTo: view.rightAnchor), | |
bottomAnchor.constraint(equalTo: view.bottomAnchor) | |
]) | |
} | |
func constrainToCenter(of view: UIView) { | |
translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
centerXAnchor.constraint(equalTo: view.centerXAnchor), | |
centerYAnchor.constraint(equalTo: view.centerYAnchor), | |
]) | |
} | |
func constrain(to size: CGSize) { | |
translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
widthAnchor.constraint(equalToConstant: size.width), | |
heightAnchor.constraint(equalToConstant: size.height), | |
]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment