iosswiftuiscrollviewdynamic-controls

Dynamically add various controls to scrollview (iOS/Swift)


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.

How do I add dynamic controls to a scrollview?

Things I tried:

enter image description here


Solution

  • It would appear this IS the correct way to do it. Apparently the text is white by default so I couldn't see the button.

    Adding this line

    button.backgroundColor = UIColor.blackColor()
    

    made the button visible. As my question asks for how to add various controls this can be done and still follow autolayout views by using constraints programatically. There is a good video on the topic here (https://www.youtube.com/watch?v=Bl_YZLKPg1c), make sure to watch part 1 as well.