---
title: NSTextField
framework: appkit
role: symbol
role_heading: Class
path: appkit/nstextfield
---

# NSTextField

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

## Declaration

```swift
class NSTextField
```

## Mentioned in

Adding Writing Tools support to a custom AppKit view Adopting the system text cursor in custom text views Customizing Writing Tools behavior for AppKit views

## Overview

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

- [init(labelWithAttributedString:)](appkit/nstextfield/init(labelwithattributedstring:).md)
- [init(labelWithString:)](appkit/nstextfield/init(labelwithstring:).md)
- [init(string:)](appkit/nstextfield/init(string:).md)
- [init(wrappingLabelWithString:)](appkit/nstextfield/init(wrappinglabelwithstring:).md)

### Controlling Selection and Editing

- [isSelectable](appkit/nstextfield/isselectable.md)
- [isEditable](appkit/nstextfield/iseditable.md)

### Controlling Rich Text Behavior

- [allowsEditingTextAttributes](appkit/nstextfield/allowseditingtextattributes.md)
- [importsGraphics](appkit/nstextfield/importsgraphics.md)

### Setting Placeholder Text

- [placeholderString](appkit/nstextfield/placeholderstring.md)
- [placeholderAttributedString](appkit/nstextfield/placeholderattributedstring.md)

### Configuring Line Wrapping

- [lineBreakStrategy](appkit/nstextfield/linebreakstrategy.md)
- [allowsDefaultTighteningForTruncation](appkit/nstextfield/allowsdefaulttighteningfortruncation.md)
- [maximumNumberOfLines](appkit/nstextfield/maximumnumberoflines.md)

### Sizing with Auto Layout

- [preferredMaxLayoutWidth](appkit/nstextfield/preferredmaxlayoutwidth.md)

### Setting the Text Color

- [textColor](appkit/nstextfield/textcolor.md)

### Controlling the Background

- [backgroundColor](appkit/nstextfield/backgroundcolor.md)
- [drawsBackground](appkit/nstextfield/drawsbackground.md)
- [isBezeled](appkit/nstextfield/isbezeled.md)
- [bezelStyle](appkit/nstextfield/bezelstyle-swift.property.md)
- [NSTextField.BezelStyle](appkit/nstextfield/bezelstyle-swift.enum.md)

### Setting a Border

- [isBordered](appkit/nstextfield/isbordered.md)

### Selecting the Text

- [selectText(_:)](appkit/nstextfield/selecttext(_:).md)

### Working with the Responder Chain

- [acceptsFirstResponder](appkit/nstextfield/acceptsfirstresponder.md)

### Using Keyboard Interface Control

- [allowsCharacterPickerTouchBarItem](appkit/nstextfield/allowscharacterpickertouchbaritem.md)

### Supporting Text Completion and Suggestions

- [isAutomaticTextCompletionEnabled](appkit/nstextfield/isautomatictextcompletionenabled.md)
- [NSTextSuggestionsDelegate](appkit/nstextsuggestionsdelegate.md)
- [NSSuggestionItem](appkit/nssuggestionitem.md)
- [NSSuggestionItemResponse](appkit/nssuggestionitemresponse.md)
- [NSSuggestionItemSection](appkit/nssuggestionitemsection.md)

### Setting the Delegate

- [delegate](appkit/nstextfield/delegate.md)

### Implementing Delegate Methods

- [textShouldBeginEditing(_:)](appkit/nstextfield/textshouldbeginediting(_:).md)
- [textDidBeginEditing(_:)](appkit/nstextfield/textdidbeginediting(_:).md)
- [textDidChange(_:)](appkit/nstextfield/textdidchange(_:).md)
- [textShouldEndEditing(_:)](appkit/nstextfield/textshouldendediting(_:).md)
- [textDidEndEditing(_:)](appkit/nstextfield/textdidendediting(_:).md)

### Instance Properties

- [allowsCharacterPickerTouchBarItem](appkit/nstextfield/allowscharacterpickertouchbaritem.md)
- [allowsWritingTools](appkit/nstextfield/allowswritingtools.md)
- [allowsWritingToolsAffordance](appkit/nstextfield/allowswritingtoolsaffordance.md)
- [placeholderAttributedStrings](appkit/nstextfield/placeholderattributedstrings.md)
- [placeholderStrings](appkit/nstextfield/placeholderstrings.md)
- [resolvesNaturalAlignmentWithBaseWritingDirection](appkit/nstextfield/resolvesnaturalalignmentwithbasewritingdirection.md)
- [suggestionsDelegate](appkit/nstextfield/suggestionsdelegate.md)

## Relationships

### Inherits From

- [NSControl](appkit/nscontrol.md)

### Inherited By

- [NSComboBox](appkit/nscombobox.md)
- [NSSearchField](appkit/nssearchfield.md)
- [NSSecureTextField](appkit/nssecuretextfield.md)
- [NSTokenField](appkit/nstokenfield.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSAccessibilityElementProtocol](appkit/nsaccessibilityelementprotocol.md)
- [NSAccessibilityNavigableStaticText](appkit/nsaccessibilitynavigablestatictext.md)
- [NSAccessibilityProtocol](appkit/nsaccessibilityprotocol.md)
- [NSAccessibilityStaticText](appkit/nsaccessibilitystatictext.md)
- [NSAnimatablePropertyContainer](appkit/nsanimatablepropertycontainer.md)
- [NSAppearanceCustomization](appkit/nsappearancecustomization.md)
- [NSCoding](foundation/nscoding.md)
- [NSDraggingDestination](appkit/nsdraggingdestination.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [NSTextContent](appkit/nstextcontent.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [NSUserActivityRestoring](appkit/nsuseractivityrestoring.md)
- [NSUserInterfaceItemIdentification](appkit/nsuserinterfaceitemidentification.md)
- [NSUserInterfaceValidations](appkit/nsuserinterfacevalidations.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Text views

- [NSTextFieldDelegate](appkit/nstextfielddelegate.md)
- [NSTextView](appkit/nstextview.md)
- [NSTextViewDelegate](appkit/nstextviewdelegate.md)
- [NSTextDelegate](appkit/nstextdelegate.md)
- [NSText](appkit/nstext.md)
