Swift: Create button that leads to new view -


i wanted know how i'd programmatically, without use of storyboard, able make button when pressed leads viewcontroller.

let button = uibutton(type: uibuttontype.system) button.settitle("button", forstate: uicontrolstate.normal) button.sizetofit() button.addtarget(self, action: "loadviewcontroller", forcontrolevents: uicontrolevents.touchupinside) self.view.addsubview(button) 

loadviewcontroller method in controller loads view controller.

func loadviewcontroller() {     let vc = uiviewcontroller(nibname: "viewcontroller", bundle: nil)     self.presentviewcontroller(vc, animated: true, completion:nil) } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

dataset - MPAndroidchart returning no chart Data available -

post - imageshack API cURL -