Setting a Button’s Title

A button can have two titles associated with it: normal and alternate. If the button type is NSMomentaryPushInButton, NSPushOnPushOffButton, NSMomentaryLightButton, or NSOnOffButton, only the normal title is ever displayed. If the button type is NSMomentaryChangeButton or NSToggleButton, the normal title is displayed when the button’s state is off (NSOffState )and the alternate title is displayed when the button’s state is on or mixed (NSOnState. or NSMixedState). If you want a button to display different titles for all three states, you must subclass NSButton.

If you want the title to contain plain text, use setTitle: to set the normal title and setAlternateTitle: to set the alternate title. If you want the title to contain styled text (for example, italics or bold), use setAttributedTitle: and setAttributedAlternateTitle:.

To set how the title is positioned relative to the button’s image, use setImagePosition:, described in “Setting a Button’s Image.” If there is no image, the title is centered horizontally and vertically within the button. If the title is above, below, or overlapping the image, the title is centered horizontally within the button. To hide the title, use setImagePosition: with an argument of NSImageOnly.

To set the title’s font, send setFont: to the button’s button cell.

If you want a button to display its title in a tag when the mouse is over it, you need to use Tool Tips.