Dynamically add various controls to scrollview (iOS/Swift) -


i'm working on web application allows users customize fields want retrieve users. example, text, numbers, booleans, popups. because unknown amount of controls need decided create reference scrollview. tried adding button test can't figure out how button show up? when view page see white.

how add dynamic controls scrollview?

things tried:

  • made sure autolayout correct scrollview.
  • the addsubview code below.

    import uikit class taskdetailviewcontroller: uiviewcontroller {       @iboutlet weak var thescrollview: uiscrollview!      override func viewdidload() {         super.viewdidload()          // additional setup after loading 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 resources can recreated.     }       /*     // mark: - navigation      // in storyboard-based application, want little preparation before navigation     override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         // new view controller using segue.destinationviewcontroller.         // pass selected object new view controller.     }     */  } 

enter image description here

it appear correct way it. apparently text white default couldn't see button.

adding line

button.backgroundcolor = uicolor.blackcolor() 

made button visible. question asks how add various controls can done , still follow autolayout views using constraints programatically. there video on topic here (https://www.youtube.com/watch?v=bl_yzlkpg1c), make sure watch part 1 well.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo