Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.


Inherits From: NSControl : NSView : NSResponder : NSObject

Conforms To: NSCoding (NSResponder) NSObject (NSObject)

Declared In: AppKit/NSButton.h

Class Description

NSButton is a subclass of NSControl that intercepts mouse-down events and sends an action message to a target object when it's clicked or pressed. By virtue of its NSButtonCell, NSButton is a two-state NSControlit's either off or onand it displays its state depending on the configuration of the NSButtonCell. NSButton acquires other attributes of NSButtonCell. The state is used as the value, so NSControl methods like setIntValue: actually set the state (the methods setState: and state are provided as a more conceptually accurate way of setting and getting the state). The NSButton can send its action continuously and display highlighting in several different ways. What's more, an NSButton can have a key equivalent that's eligible for triggering whenever the NSButton's NSPanel or NSWindow is the key window.

NSButton and NSMatrix both provide a control view, which is needed to display an NSButtonCell object. However, while NSMatrix requires you to access the NSButtonCells directly, most of NSButton's methods are covers for identically declared methods in NSButtonCell. (In other words, the implementation of the NSButton method invokes the corresponding NSButtonCell method for you, allowing you to be unconcerned with the NSButtonCell's existence.) The only NSButtonCell methods that don't have covers relate to the font used to display the key equivalent, and to specific methods for highlighting or showing the NSButton's state (these last are usually set together with NSButton's setType: method).

Creating a Subclass of NSButton

Override the designated initializer (NSView's initWithFrame: method) if you create a subclass of NSButton that performs its own initialization. If you want to use a custom NSButtonCell subclass with your subclass of NSButton, you have to override the setCellClass: method, as described in Creating New NSControls in the NSControl class specification.

See the NSButtonCell class specification for more on NSButton's behavior.

Initializing the NSButton Factory

+ (void)setCellClass:(Class)classId Sets the subclass of NSButtonCell used by NSButton.

Setting the Button Type

Setting the State

Setting the Repeat Interval

Setting the Images

Modifying Graphic Attributes


Setting the Key Equivalent

- (NSString *)keyEquivalent Returns the button's key equivalent.

- (unsigned int)keyEquivalentModifierMask Returns the mask indicating the possible modifier keys for button's key equivalent.

- (void)setKeyEquivalent:(NSString *)aKeyEquivalent

Makes aKeyEquivalent the button's key equivalent.

- (void)setKeyEquivalentModifierMask:(unsigned int)mask

Sets the mask that determines the possible modifier keys for button's key equivalent.

Handling Events and Action Messages