How to connect outlets and actions in Swift / MacOS programaticly

别等时光非礼了梦想. 提交于 2019-12-01 20:31:31

If you want to use storyboard and lay out all your elements there, you can't really avoid the ctrl drag (or just drag if you open the connections inspector on the right).

You could however create your second button programmatically in code and not use the storyboard at all for it. Then programmatically add your constraints too.

You can also add the action of the button programmatically (using addTarget) if you would like but that would require at least the IBOutlet to be setup in order to have a reference to the button.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!