Last active
April 26, 2017 14:57
-
-
Save ConorBrady/ebfc3ac799c2c7e1891b12053aaef23a 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
protocol HasModel { | |
associatedtype Model | |
var model: Model? { get set } | |
} | |
protocol HasHeight { | |
static var height: CGFloat { get } | |
} | |
extension UIView { | |
func enableConstraints() -> Self { | |
return self <== { | |
$0.translatesAutoresizingMaskIntoConstraints = false | |
} | |
} | |
func layout(center child: UIView) -> UIView { | |
child.enableConstraints() | |
addSubview(child) | |
NSLayoutConstraint.activate([ | |
centerXAnchor.constraint(equalTo: child.centerXAnchor), | |
centerYAnchor.constraint(equalTo: child.centerYAnchor) | |
]) | |
return self | |
} | |
func layout(width: CGFloat, height: CGFloat) -> UIView { | |
enableConstraints() | |
NSLayoutConstraint.activate([ | |
widthAnchor.constraint(equalToConstant: width), | |
heightAnchor.constraint(equalToConstant: height) | |
]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment