Dynamically add various controls to scrollview (iOS/Swift)
<p>I'm working on a web application which allows the users to customize the fields they want to retrieve from their users.  For example, text, numbers, booleans, popups.  Because its unknown the amount of controls I need decided to create a reference to a scrollview.  I tried adding a button as a test but I can't figure out how to get the button to show up? When I view the page I see just white.</p>

<p><strong>How do I add dynamic controls to a scrollview?</strong></p>

<p>Things I tried:</p>

<ul>
<li>Made sure AutoLayout is correct for the scrollView.</li>
<li><p>The addSubview code below.</p>

<pre><code>import UIKit
class TaskDetailViewController: UIViewController {


    @IBOutlet weak var theScrollView: UIScrollView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //self.view.addSubview(UIButton)

        let cellButton = UIButton(frame: CGRectMake(5, 5, 50, 30))
        cellButton.setTitle("hello", forState: UIControlState.Normal)

        theScrollView.addSubview(cellButton)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
</code></pre></li>
</ul>

<p><a href="https://i.stack.imgur.com/TPbCx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TPbCx.png" alt="enter image description here"></a></p>