Created
January 22, 2017 00:55
-
-
Save joamafer/56368f55131f2e4170d9ac482b7c0064 to your computer and use it in GitHub Desktop.
Add child UIViewController to UIView
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 add(viewController: UIViewController, toContainerView containerView: UIView) { | |
viewController.view.translatesAutoresizingMaskIntoConstraints = false | |
addChildViewController(viewController) | |
containerView.addSubview(viewController.view) | |
viewController.didMove(toParentViewController: self) | |
viewController.view.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true | |
viewController.view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor).isActive = true | |
viewController.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true | |
viewController.view.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment