Created
March 23, 2019 23:55
-
-
Save romyilano/f55d66db2ad59b68f7ab391a8f81a49e to your computer and use it in GitHub Desktop.
Handling container views in code
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
// thanks dude | |
// https://medium.com/@dushyant_db/setting-up-a-container-view-using-interface-builder-and-via-code-7ac1a7f0a0d6 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController else { | |
return | |
} | |
addChildViewController(childVC) | |
//Or, you could add auto layout constraint instead of relying on AutoResizing contraints | |
childVC.view.autoresizingMask = [.flexibleHeight, .flexibleWidth] | |
childVC.view.frame = containerView.bounds | |
containerView.addSubview(childVC.view) | |
childVC.didMove(toParentViewController: self) | |
//Some property on ChildVC that needs to be set | |
childVC.dataSource = self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment