Created
June 1, 2020 15:50
-
-
Save ChrisMarshallNY/09a54c925637a0e7ee68c1d9cb245bde to your computer and use it in GitHub Desktop.
UIView Extension to Add An Auto-Layout SubView With Equal All-Around Constraints (Fill)
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 { | |
/* ################################################################## */ | |
/** | |
This allows us to add a subview, and set it up with auto-layout constraints to fill the superview. | |
- parameter inSubview: The subview we want to add. | |
*/ | |
func addContainedView(_ inSubView: UIView) { | |
addSubview(inSubView) | |
inSubView.translatesAutoresizingMaskIntoConstraints = false | |
inSubView.topAnchor.constraint(equalTo: topAnchor, constant: 0).isActive = true | |
inSubView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0).isActive = true | |
inSubView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true | |
inSubView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment