ios - Programmatically adding buttons to ScrollView (initially created with IB) -


i'm doing majority of work in ib, , created uiscrollview (with child view) using ib add uibuttons (with corresponding constraints). add few of these buttons using ib, want add hundreds of these buttons single uiscrollview using ib seems tedious.

hence, want programmatically add buttons (can copy/paste button labels .txt file have) in .swift file.

how reference uiscrollview created in ib, in corresponding .swift file, can add these buttons? see below code , comment:

override func viewdidload() {         super.viewdidload()         let nib = uinib(nibname: "keyboardview", bundle: nil)         let objects = nib.instantiatewithowner(self, options: nil)         view = objects[0] as! uiview;      let buttontitles = ["test quote 1", "test quote 2"]     var buttons = createbuttons(buttontitles)     var toprow = uiview(frame: cgrectmake(0, 0, 320, 40))      button in buttons {         toprow.addsubview(button)     }      self.view.addsubview(toprow) // how add toprow view scrollview created in ib, rather main view?      addconstraints(buttons, containingview: toprow)  } 

if need add hundreds of buttons, maybe use uitableview instead of uiscrollview need create 1 custom uitableviewcell , use datasource configurating uibuttons.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -