Class

NSTextField

Text that the user can select or edit and that sends its action message to its target when the user presses the Return key.

Declaration

@interface NSTextField : NSControl

Overview

The NSTextField class uses the NSTextFieldCell class to implement its user interface.

The parent class, NSControl, provides the methods for setting the values of the text field, such as stringValue and doubleValue. There are corresponding methods to retrieve values.

Topics

Controlling Selection and Editing

editable

A Boolean that controls whether the user can edit the receiver’s text.

selectable

A Boolean that determins whether the receiver is selectable (but not editable).

Controlling Rich Text Behavior

allowsEditingTextAttributes

A Boolean that controls whether the receiver allows the user to change font attributes of the receiver’s string.

importsGraphics

A Boolean that controls whether the receiver allows the user to drag image files into it.

Setting the Text Color

textColor

The color used to draw the receiver’s text.

Auto Layout Sizing

preferredMaxLayoutWidth

The preferred maximum layout width.

Controlling the Background

backgroundColor

The color of the background that the receiver’s cell draws behind the text.

drawsBackground

A Boolean that controls whether the receiver’s cell draws its background color behind its text

Setting a Border

bezeled

A Boolean that controls whether the receiver draws a bezeled border around its contents.

bezelStyle

The receiver’s bezel style.

bordered

A Boolean that controls whether the receiver draws a solid black border around its contents.

Selecting the Text

- selectText:

Ends editing and selects the entire contents of the receiver if it’s selectable.

Working with the Responder Chain

acceptsFirstResponder

A Boolean value indicating whether the receiver is editable.

Using Keyboard Interface Control

- setTitleWithMnemonic:

Sets the receiver’s string value, using the embedded character as the keyboard mnemonic.

Deprecated

Setting the Delegate

delegate

The receiver’s delegate.

NSText Delegate Method Implementations

- textShouldBeginEditing:

Requests permission to begin editing a text object.

- textDidBeginEditing:

Posts a notification that the text is about to begin editing to the default notification center.

- textDidChange:

Posts a notification that the text has changed and forwards this message to the receiver’s cell if it responds.

- textShouldEndEditing:

Performs validation on the receiver’s new value.

- textDidEndEditing:

Handles an end of editing.

See Also

Text Views

NSTextFieldDelegate

A protocol that a text field delegate can use to control its field editor action menu.

NSTextView

A view that draws text and handles user interactions with that text.

NSTextViewDelegate

A set of optional methods that text view delegates can use to manage selection, set text attributes, work with the spell checker, and more.

NSText

The most general programmatic interface for objects that manage text.