Next: 3.3 Putting the button Up: 3 Adding a Button Previous: 3.1 A Quick Introduction

3.2 Creating a Button

Creating a button is quite easy:
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)



2008-01-16