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


class NSTextField : NSControl


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.


Controlling Selection and Editing

var isEditable: Bool

A Boolean that controls whether the user can edit the value in the text field.

var isSelectable: Bool

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

Controlling Rich Text Behavior

var allowsEditingTextAttributes: Bool

A Boolean that controls whether the user can change font attributes of the text field’s string.

var importsGraphics: Bool

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

Setting the Text Color

var textColor: NSColor?

The color used to draw the receiver’s text.

Auto Layout Sizing

var preferredMaxLayoutWidth: CGFloat

The preferred maximum layout width.

Controlling the Background

var backgroundColor: NSColor?

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

var drawsBackground: Bool

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

Setting a Border

var isBezeled: Bool

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

var bezelStyle: NSTextField.BezelStyle

The receiver’s bezel style.

var isBordered: Bool

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

Selecting the Text

func selectText(Any?)

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

Working with the Responder Chain

var acceptsFirstResponder: Bool

A Boolean value indicating whether the receiver is editable.

Setting the Delegate

var delegate: NSTextFieldDelegate?

The receiver’s delegate.

NSText Delegate Method Implementations

func textShouldBeginEditing(NSText) -> Bool

Requests permission to begin editing a text object.

func textDidBeginEditing(Notification)

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

func textDidChange(Notification)

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

func textShouldEndEditing(NSText) -> Bool

Performs validation on the receiver’s new value.

func textDidEndEditing(Notification)

Handles an end of editing.


enum NSTextField.BezelStyle

Specify the bezel style of the text field cell.

See Also

Text Views

protocol NSTextFieldDelegate

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

class NSTextView

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

protocol 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.

protocol NSTextDelegate

A set of optional methods implemented by the delegate of an NSText object to edit text and change text formats.

class NSText

The most general programmatic interface for objects that manage text.