<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextField",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextField"
  },
  "title" : "NSTextField"
}
-->

# NSTextField

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

```
class NSTextField
```

## Overview

The [`NSTextField`](/documentation/AppKit/NSTextField) class uses the [`NSTextFieldCell`](/documentation/AppKit/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`](/documentation/AppKit/NSControl), provides the methods for setting the values of the text field, such as [`stringValue`](/documentation/AppKit/NSControl/stringValue) and [`doubleValue`](/documentation/AppKit/NSControl/doubleValue). There are corresponding methods to retrieve values.

## Topics

### Creating text fields

[`+  labelWithAttributedString:`](/documentation/AppKit/NSTextField/init(labelWithAttributedString:))

Creates a text field for use as a static label that displays styled text, doesn’t wrap, and doesn’t have selectable text.

[`+  labelWithString:`](/documentation/AppKit/NSTextField/init(labelWithString:))

Initializes a text field for use as a static label that uses the system default font, doesn’t wrap, and doesn’t have selectable text.

[`+  textFieldWithString:`](/documentation/AppKit/NSTextField/init(string:))

Initializes a single-line editable text field for user input using the system default font and standard visual appearance.

[`+  wrappingLabelWithString:`](/documentation/AppKit/NSTextField/init(wrappingLabelWithString:))

Initializes a text field for use as a multiline static label with selectable text that uses the system default font.

### Controlling selection and editing

[`selectable`](/documentation/AppKit/NSTextField/isSelectable)

A Boolean value that determines whether the user can select the content of the text field.

[`editable`](/documentation/AppKit/NSTextField/isEditable)

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

### Controlling rich text behavior

[`allowsEditingTextAttributes`](/documentation/AppKit/NSTextField/allowsEditingTextAttributes)

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

[`importsGraphics`](/documentation/AppKit/NSTextField/importsGraphics)

A Boolean value that controls whether the user can drag image files into the text field.

### Setting placeholder text

[`placeholderString`](/documentation/AppKit/NSTextField/placeholderString)

The string the text field displays when empty to help the user understand the text field’s purpose.

[`placeholderAttributedString`](/documentation/AppKit/NSTextField/placeholderAttributedString)

The attributed string the text field displays when empty to help the user understand the text field’s purpose.

[`placeholderStrings`](/documentation/AppKit/NSTextField/placeholderStrings)

[`placeholderAttributedStrings`](/documentation/AppKit/NSTextField/placeholderAttributedStrings)

### Configuring line wrapping

[`lineBreakStrategy`](/documentation/AppKit/NSTextField/lineBreakStrategy)

The strategy that the system uses to break lines when laying out multiple lines of text.

[`allowsDefaultTighteningForTruncation`](/documentation/AppKit/NSTextField/allowsDefaultTighteningForTruncation)

A Boolean value that controls whether single-line text fields tighten intercharacter spacing before truncating the text.

[`maximumNumberOfLines`](/documentation/AppKit/NSTextField/maximumNumberOfLines)

The maximum number of lines a wrapping text field displays before clipping or truncating the text.

### Setting the text alignment

[`resolvesNaturalAlignmentWithBaseWritingDirection`](/documentation/AppKit/NSTextField/resolvesNaturalAlignmentWithBaseWritingDirection)

Specifies the behavior for resolving [`NSTextAlignment.natural`](/documentation/AppKit/NSTextAlignment/natural) to the visual alignment.

### Sizing with Auto Layout

[`preferredMaxLayoutWidth`](/documentation/AppKit/NSTextField/preferredMaxLayoutWidth)

The maximum width of the text field’s intrinsic content size.

### Setting the text color

[`textColor`](/documentation/AppKit/NSTextField/textColor)

The color of the text field’s content.

### Controlling the background

[`backgroundColor`](/documentation/AppKit/NSTextField/backgroundColor)

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

[`drawsBackground`](/documentation/AppKit/NSTextField/drawsBackground)

A Boolean value that controls whether the text field’s cell draws a background color behind the text.

[`bezeled`](/documentation/AppKit/NSTextField/isBezeled)

A Boolean value that controls whether the text field draws a bezeled background around its contents.

[`bezelStyle`](/documentation/AppKit/NSTextField/bezelStyle-swift.property)

The text field’s bezel style, square or rounded.

[`BezelStyle`](/documentation/AppKit/NSTextField/BezelStyle-swift.enum)

The style of bezel the text field displays.

### Setting a border

[`bordered`](/documentation/AppKit/NSTextField/isBordered)

A Boolean value that controls whether the text field draws a solid black border around its contents.

[`borderShape`](/documentation/AppKit/NSTextField/borderShape)

Set border shape
`NSControlBorderShapeAutomatic` sets text field or subclass to default system shape.
`NSControlBorderShapeCircle` sets text field or subclass to `NSControlBorderShapeAutomatic`.

### Selecting the text

[`-  selectText:`](/documentation/AppKit/NSTextField/selectText(_:))

Ends editing in the text field and, if it’s selectable, selects the entire text content.

### Working with the responder chain

[`acceptsFirstResponder`](/documentation/AppKit/NSTextField/acceptsFirstResponder)

A Boolean value that indicates whether the text field is editable and accepts first responder status.

### Using keyboard interface control

[`allowsCharacterPickerTouchBarItem`](/documentation/AppKit/NSTextField/allowsCharacterPickerTouchBarItem)

A Boolean value that controls whether the Touch Bar displays the character picker item for rich text fields.

[`-  setTitleWithMnemonic:`](/documentation/AppKit/NSTextField/setTitleWithMnemonic:)

Sets the text field’s string value using the embedded character as the keyboard mnemonic.

### Supporting text completion and suggestions

[`automaticTextCompletionEnabled`](/documentation/AppKit/NSTextField/isAutomaticTextCompletionEnabled)

A Boolean value that indicates whether the text field automatically completes text as the user types.

[`suggestionsDelegate`](/documentation/AppKit/NSTextField/suggestionsDelegate)

The delegate that provides text suggestions for the receiving text field and responds to the user highlighting and selecting items.

[`NSTextSuggestionsDelegate`](/documentation/AppKit/NSTextSuggestionsDelegate)

A protocol for suggestion delegates of text fields to conform to in order to provide text suggestions in response to the user typing.

[`NSSuggestionItem`](/documentation/AppKit/NSSuggestionItem)

The items that appear in suggestion menus.

[`NSSuggestionItemResponse`](/documentation/AppKit/NSSuggestionItemResponse)

Describes the result of a batch of suggestion items from a search

[`NSSuggestionItemSection`](/documentation/AppKit/NSSuggestionItemSection)

Describes a section of suggestions items in a suggestions menu

### Supporting Writing Tools

[`allowsWritingTools`](/documentation/AppKit/NSTextField/allowsWritingTools)

[`allowsWritingToolsAffordance`](/documentation/AppKit/NSTextField/allowsWritingToolsAffordance)

### Setting the delegate

[`delegate`](/documentation/AppKit/NSTextField/delegate)

The text field’s delegate.

### Implementing delegate methods

[`-  textShouldBeginEditing:`](/documentation/AppKit/NSTextField/textShouldBeginEditing(_:))

Requests permission to begin editing a text object.

[`-  textDidBeginEditing:`](/documentation/AppKit/NSTextField/textDidBeginEditing(_:))

Posts a notification to the default notification center that the text is about to go into edit mode.

[`-  textDidChange:`](/documentation/AppKit/NSTextField/textDidChange(_:))

Posts a notification when the text changes, and forwards the message to the text field’s cell if it responds.

[`-  textShouldEndEditing:`](/documentation/AppKit/NSTextField/textShouldEndEditing(_:))

Performs validation on the text field’s new value.

[`-  textDidEndEditing:`](/documentation/AppKit/NSTextField/textDidEndEditing(_:))

Posts a notification when the text is no longer in edit mode.

## Relationships

### Conforms To

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`NSAppearanceCustomization`](/documentation/AppKit/NSAppearanceCustomization)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSAccessibilityNavigableStaticText`](/documentation/AppKit/NSAccessibilityNavigableStaticText)

[`NSTextContent`](/documentation/AppKit/NSTextContent)

[`NSAccessibilityElementProtocol`](/documentation/AppKit/NSAccessibilityElementProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSDraggingDestination`](/documentation/AppKit/NSDraggingDestination)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSUserInterfaceItemIdentification`](/documentation/AppKit/NSUserInterfaceItemIdentification)

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`NSAccessibilityProtocol`](/documentation/AppKit/NSAccessibilityProtocol)

[`NSStandardKeyBindingResponding`](/documentation/AppKit/NSStandardKeyBindingResponding)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSUserActivityRestoring`](/documentation/AppKit/NSUserActivityRestoring)

[`NSAccessibilityStaticText`](/documentation/AppKit/NSAccessibilityStaticText)

[`NSAnimatablePropertyContainer`](/documentation/AppKit/NSAnimatablePropertyContainer)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSUserInterfaceValidations`](/documentation/AppKit/NSUserInterfaceValidations)

### Inherited By

[`NSSearchField`](/documentation/AppKit/NSSearchField)

[`NSComboBox`](/documentation/AppKit/NSComboBox)

[`NSTokenField`](/documentation/AppKit/NSTokenField)

[`NSSecureTextField`](/documentation/AppKit/NSSecureTextField)

### Inherits From

[`NSControl`](/documentation/AppKit/NSControl)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)