---
title: NSText
framework: appkit
role: symbol
role_heading: Class
path: appkit/nstext
---

# NSText

The most general programmatic interface for objects that manage text.

## Declaration

```swift
class NSText
```

## Overview

Overview NSText draws text for user interface objects, provides text editing capabilities, and controls text attributes such as type size, font, and color. NSText initialization creates an instance of a concrete subclass, such as NSTextView (generically called a text object). In general, you’re more likely to use the NSTextView subclass, because it extends the interface declared by NSText and provides much more sophisticated functionality than that declared in NSText. AppKit uses text objects wherever text appears in interface objects. For example, a text object draws the title of a window, the commands in a menu, the title of a button, and the items in a browser. Your app can also create text objects for its own purposes.

## Topics

### Creating a Text Object

- [init(coder:)](appkit/nstext/init(coder:).md)
- [init(frame:)](appkit/nstext/init(frame:).md)

### Getting the characters

- [string](appkit/nstext/string.md)

### Setting graphics attributes

- [backgroundColor](appkit/nstext/backgroundcolor.md)
- [drawsBackground](appkit/nstext/drawsbackground.md)

### Setting behavioral attributes

- [isEditable](appkit/nstext/iseditable.md)
- [isSelectable](appkit/nstext/isselectable.md)
- [isFieldEditor](appkit/nstext/isfieldeditor.md)
- [isRichText](appkit/nstext/isrichtext.md)
- [importsGraphics](appkit/nstext/importsgraphics.md)

### Using the Font panel and menu

- [usesFontPanel](appkit/nstext/usesfontpanel.md)

### Using the ruler

- [toggleRuler(_:)](appkit/nstext/toggleruler(_:).md)
- [isRulerVisible](appkit/nstext/isrulervisible.md)

### Changing the selection

- [selectedRange](appkit/nstext/selectedrange.md)

### Replacing text

- [replaceCharacters(in:withRTF:)](appkit/nstext/replacecharacters(in:withrtf:).md)
- [replaceCharacters(in:withRTFD:)](appkit/nstext/replacecharacters(in:withrtfd:).md)
- [replaceCharacters(in:with:)](appkit/nstext/replacecharacters(in:with:).md)

### Action methods for editing

- [selectAll(_:)](appkit/nstext/selectall(_:).md)
- [copy(_:)](appkit/nstext/copy(_:).md)
- [cut(_:)](appkit/nstext/cut(_:).md)
- [paste(_:)](appkit/nstext/paste(_:).md)
- [copyFont(_:)](appkit/nstext/copyfont(_:).md)
- [pasteFont(_:)](appkit/nstext/pastefont(_:).md)
- [copyRuler(_:)](appkit/nstext/copyruler(_:).md)
- [pasteRuler(_:)](appkit/nstext/pasteruler(_:).md)
- [delete(_:)](appkit/nstext/delete(_:).md)

### Changing the font

- [changeFont(_:)](appkit/nstext/changefont(_:).md)
- [font](appkit/nstext/font.md)
- [setFont(_:range:)](appkit/nstext/setfont(_:range:).md)

### Setting text alignment

- [alignment](appkit/nstext/alignment.md)
- [alignCenter(_:)](appkit/nstext/aligncenter(_:).md)
- [alignLeft(_:)](appkit/nstext/alignleft(_:).md)
- [alignRight(_:)](appkit/nstext/alignright(_:).md)

### Setting text color

- [textColor](appkit/nstext/textcolor.md)
- [setTextColor(_:range:)](appkit/nstext/settextcolor(_:range:).md)

### Writing direction

- [baseWritingDirection](appkit/nstext/basewritingdirection.md)

### Setting superscripting and subscripting

- [superscript(_:)](appkit/nstext/superscript(_:).md)
- [subscript(_:)](appkit/nstext/subscript(_:).md)
- [unscript(_:)](appkit/nstext/unscript(_:).md)

### Underlining text

- [underline(_:)](appkit/nstext/underline(_:).md)

### Reading and writing RTF files

- [readRTFD(fromFile:)](appkit/nstext/readrtfd(fromfile:).md)
- [writeRTFD(toFile:atomically:)](appkit/nstext/writertfd(tofile:atomically:).md)
- [rtfd(from:)](appkit/nstext/rtfd(from:).md)
- [rtf(from:)](appkit/nstext/rtf(from:).md)

### Checking spelling

- [checkSpelling(_:)](appkit/nstext/checkspelling(_:).md)
- [showGuessPanel(_:)](appkit/nstext/showguesspanel(_:).md)

### Constraining size

- [maxSize](appkit/nstext/maxsize.md)
- [minSize](appkit/nstext/minsize.md)
- [isVerticallyResizable](appkit/nstext/isverticallyresizable.md)
- [isHorizontallyResizable](appkit/nstext/ishorizontallyresizable.md)
- [sizeToFit()](appkit/nstext/sizetofit().md)

### Scrolling

- [scrollRangeToVisible(_:)](appkit/nstext/scrollrangetovisible(_:).md)

### Setting the delegate

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

### Constants

- [NSTextAlignment](appkit/nstextalignment.md)
- [NSWritingDirection](appkit/nswritingdirection.md)
- [Movement Codes](appkit/movement-codes.md)
- [Common Unicode Characters](appkit/common-unicode-characters.md)

### Notifications

- [didBeginEditingNotification](appkit/nstext/didbegineditingnotification.md)
- [didChangeNotification](appkit/nstext/didchangenotification.md)
- [didEndEditingNotification](appkit/nstext/didendeditingnotification.md)
- [movementUserInfoKey](appkit/nstext/movementuserinfokey.md)
- [NSTextMovement](appkit/nstextmovement.md)

## Relationships

### Inherits From

- [NSView](appkit/nsview.md)

### Inherited By

- [NSTextView](appkit/nstextview.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)
- [NSAccessibilityProtocol](appkit/nsaccessibilityprotocol.md)
- [NSAnimatablePropertyContainer](appkit/nsanimatablepropertycontainer.md)
- [NSAppearanceCustomization](appkit/nsappearancecustomization.md)
- [NSChangeSpelling](appkit/nschangespelling.md)
- [NSCoding](foundation/nscoding.md)
- [NSDraggingDestination](appkit/nsdraggingdestination.md)
- [NSIgnoreMisspelledWords](appkit/nsignoremisspelledwords.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [NSUserActivityRestoring](appkit/nsuseractivityrestoring.md)
- [NSUserInterfaceItemIdentification](appkit/nsuserinterfaceitemidentification.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Text views

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