Changing the size of a modal view controller : <p>Once, the user taps a button, I want my modalViewController to appear as a small square in the middle of the screen (where you can still see the original view controller in the background).</p>

<p>Almost every answer on stackoverflow I find uses the storyboard to create a modal view controller, but I've gotten this far with everything I've found.</p>

<p>When you tap the button that is supposed to bring up the modal view, this function is called: </p>

<pre><code>func didTapButton() {
    let modalViewController = ModalViewController()
    modalViewController.definesPresentationContext = true
    modalViewController.modalPresentationStyle = .overCurrentContext
    navigationController?.present(modalViewController, animated: true, completion: nil)
}
</code></pre>

<p>And the modalViewController contains:</p>

<pre><code>import UIKit

class ModalViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .blue
        view.isOpaque = false

        self.preferredContentSize = CGSize(width: 100, height: 100)

    }

}
</code></pre>

<p>Based on the answers I found, I was under the impression that if I set <code>preferredContentSize = CGSize(width: 100, height: 100)</code>, then it would make the modal view controller 100px x 100px.</p>

<p>However, the view controller takes up the entire screen (except for the tab bar because I set <code>modalViewController.modalPresentationStyle = .overCurrentContext</code></p>

<p>I'm obviously missing a step here, but I want to do everything programmatically as I'm not using the Storyboard at all in my project (except for setting the opening controller)</p>

<p>Thanks in advance for you help!!</p>
