Contents

NSTextField

Text the user can select or edit to send an action message to a target when the user presses the Return key.

Declaration

class NSTextField

Mentioned in

Overview

The NSTextField class uses the NSTextFieldCell class to implement its user interface. Text fields display text either as a static label or as an editable input field. The content of a text field is either plain text or a rich-text attributed string. Text fields also support line wrapping to display multiline text, and a variety of truncation styles if the content doesn’t fit the available space.

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.

In macOS 12 and later, if you explicitly call the layoutManager property on your text field, the framework will revert to a compatibility mode that uses NSLayoutManager. The text view also switches to this compatibility mode when it encounters text content that’s not yet supported.

Topics

Creating Text Fields

Controlling Selection and Editing

Controlling Rich Text Behavior

Setting Placeholder Text

Configuring Line Wrapping

Sizing with Auto Layout

Setting the Text Color

Controlling the Background

Setting a Border

Selecting the Text

Working with the Responder Chain

Using Keyboard Interface Control

Supporting Text Completion and Suggestions

Setting the Delegate

Implementing Delegate Methods

Instance Properties

See Also

Text views