Last active
March 13, 2019 14:21
-
-
Save rphuber/afe348df3db8bc8006a61182a51f441b 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
| func anchor(top: NSLayoutYAxisAnchor?, left: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, right: NSLayoutXAxisAnchor?, paddingTop: CGFloat, paddingLeft: CGFloat, paddingBottom: CGFloat, paddingRight: CGFloat, width: CGFloat, height: CGFloat) { | |
| translatesAutoresizingMaskIntoConstraints = false | |
| if let top = top { | |
| self.topAnchor.constraint(equalTo: top, constant: paddingTop).isActive = true | |
| } | |
| if let left = left { | |
| self.leftAnchor.constraint(equalTo: left, constant: paddingLeft).isActive = true | |
| } | |
| if let bottom = bottom { | |
| self.bottomAnchor.constraint(equalTo: bottom, constant: -paddingBottom).isActive = true | |
| } | |
| if let right = right { | |
| self.rightAnchor.constraint(equalTo: right, constant: -paddingRight).isActive = true | |
| } | |
| if width != 0 { | |
| widthAnchor.constraint(equalToConstant: width).isActive = true | |
| } | |
| if height != 0 { | |
| heightAnchor.constraint(equalToConstant: height).isActive = true | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment