Embed UIViewController inside a UIView : <p>I want to embed a UIViewController inside a UIView. I want to create this programmatically. I have created the UIViewController inside the storyboard.</p>

<p>My code to create a empty UIView:</p>

<pre><code>let myNewView=UIView(frame: CGRect(x: (0 + screenHeight / 2), y: leftView.frame.origin.y, width: screenHeight / 2, height: leftView.frame.height))
myNewView.backgroundColor=UIColor.lightGray

self.view.addSubview(myNewView)
</code></pre>

<p>And the code to append the UIViewController to the view:      </p>

<pre><code>let storyboard = UIStoryboard(name: "Main", bundle: nil)
var controller: UIViewController = storyboard.instantiateViewController(withIdentifier: "testView") as UIViewController
myNewView.addSubview(controller.view)
</code></pre>

<p>This displays the view inside my UIView, but not at the correct way. The UIView is in this case 512 pixels wide. While the (embeded) UIViewcontroller thinks that is is 1024 pixels wide (the full screen width).</p>

<p>How can I fix it that the embeded view gets the width and height from its parent (the UIView)?</p>
