Created
October 31, 2017 18:26
-
-
Save slaght/000a8735220384c6d398cdd46bf3f1f3 to your computer and use it in GitHub Desktop.
Add a subview to a parent container view and resize the parent to wrap the child
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 addSubview(subView:UIView, toView parentView:UIView) { | |
parentView.addSubview(subView) | |
var viewBindingsDict = [String: AnyObject]() | |
viewBindingsDict["subView"] = subView | |
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[subView]|", options: [], metrics: nil, views: viewBindingsDict)) | |
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[subView]|", options: [], metrics: nil, views: viewBindingsDict)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment