How to connect outlets and actions in Swift / MacOS programaticly

后端 未结 1 1254
梦谈多话
梦谈多话 2021-01-18 17:21

I have a simple example. I connected the left button1 and label1 with ctrl-draging it to the contollerclass.

How can I do the same for the right button2 label2 progr

相关标签:
1条回答
  • 2021-01-18 18:10

    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.

    0 讨论(0)
提交回复
热议问题