NSButton *myButton; myButton = AUTORELEASE ([NSButton new]); [myButton setTitle: @"Print Hello!"]; [myButton sizeToFit];setTitle: sets the title (string) to be displayed on the button; sizeToFit resizes the button so that it fits the title it is displaying.
Next, we need to set target and action of the button:
[myButton setTarget: self]; [myButton setAction: @selector (printHello:)];(self will refer to our custom object)