I want to create a custom view, say MyView, which is only containing a button and print out “hello my view” when I click it. When next time I want to use it, I just need to add a custom view to window from IB, add MyView.m into project and set the class of custom view to MyView.
My question is :
- I want to use IB to set the appearance of MyView, but I don’t know how to get the corresponding view file : MyView.m in order to use the MyView.m file next time.
You need to create the subclassed view using code; for example:
MyView.h:
MyView.m:
You need to create your custom view layout using IB and change the owning class from
NSViewtoMyView(using the 3rd tab if I recall).Then connect the
_labelfrom the owning object on the left pane (Ctrl-drag) and connect the button action to thebuttonPressed:method (Ctrl-drag).