Created
August 10, 2017 10:20
-
-
Save robnadin/f15aa8546926978251bc4c03cecb20d7 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
protocol LayoutAnchorEdgesContainer { | |
var topAnchor: NSLayoutYAxisAnchor { get } | |
var leadingAnchor: NSLayoutXAxisAnchor { get } | |
var bottomAnchor: NSLayoutYAxisAnchor { get } | |
var trailingAnchor: NSLayoutXAxisAnchor { get } | |
func pinAllEdges(to view: LayoutAnchorEdgesContainer) | |
} | |
extension LayoutAnchorEdgesContainer { | |
func pinAllEdges(to view: LayoutAnchorEdgesContainer) { | |
NSLayoutConstraint.activate([ | |
view.topAnchor.constraint(equalTo: self.topAnchor), | |
view.leadingAnchor.constraint(equalTo: self.leadingAnchor), | |
view.bottomAnchor.constraint(equalTo: self.bottomAnchor), | |
view.trailingAnchor.constraint(equalTo: self.trailingAnchor), | |
]) | |
} | |
} | |
extension UIView: LayoutAnchorEdgesContainer {} | |
extension UILayoutGuide: LayoutAnchorEdgesContainer {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment