Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created March 23, 2019 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romyilano/f55d66db2ad59b68f7ab391a8f81a49e to your computer and use it in GitHub Desktop.
Save romyilano/f55d66db2ad59b68f7ab391a8f81a49e to your computer and use it in GitHub Desktop.
Handling container views in code
// 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