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 -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -