---
title: NSTextBlock
framework: appkit
role: symbol
role_heading: Class
path: appkit/nstextblock
---

# NSTextBlock

A block of text laid out in a subregion of the text container.

## Declaration

```swift
class NSTextBlock
```

## Overview

Overview A text block appears as an attribute of a paragraph, and as part of the paragraph style. The most important subclass of NSTextBlock is NSTextTableBlock, which represents a block of text that appears as a cell in a table. The table itself is a NSTextTable object. All NSTextBlock objects reference this table, which controls their sizing and positioning.

## Topics

### Creating text blocks

- [init()](appkit/nstextblock/init().md)

### Working with dimensions of content

- [setValue(_:type:for:)](appkit/nstextblock/setvalue(_:type:for:).md)
- [value(for:)](appkit/nstextblock/value(for:).md)
- [valueType(for:)](appkit/nstextblock/valuetype(for:).md)
- [setContentWidth(_:type:)](appkit/nstextblock/setcontentwidth(_:type:).md)
- [contentWidth](appkit/nstextblock/contentwidth.md)
- [contentWidthValueType](appkit/nstextblock/contentwidthvaluetype.md)
- [NSTextBlock.Dimension](appkit/nstextblock/dimension.md)
- [NSTextBlock.ValueType](appkit/nstextblock/valuetype.md)

### Getting and setting margins, borders, and padding

- [setWidth(_:type:for:edge:)](appkit/nstextblock/setwidth(_:type:for:edge:).md)
- [setWidth(_:type:for:)](appkit/nstextblock/setwidth(_:type:for:).md)
- [width(for:edge:)](appkit/nstextblock/width(for:edge:).md)
- [widthValueType(for:edge:)](appkit/nstextblock/widthvaluetype(for:edge:).md)
- [NSTextBlock.Layer](appkit/nstextblock/layer.md)

### Getting and setting alignment

- [verticalAlignment](appkit/nstextblock/verticalalignment-swift.property.md)
- [NSTextBlock.VerticalAlignment](appkit/nstextblock/verticalalignment-swift.enum.md)

### Working with color

- [backgroundColor](appkit/nstextblock/backgroundcolor.md)
- [setBorderColor(_:for:)](appkit/nstextblock/setbordercolor(_:for:).md)
- [setBorderColor(_:)](appkit/nstextblock/setbordercolor(_:).md)

### Determining size and position of a text block

- [rectForLayout(at:in:textContainer:characterRange:)](appkit/nstextblock/rectforlayout(at:in:textcontainer:characterrange:).md)
- [boundsRect(forContentRect:in:textContainer:characterRange:)](appkit/nstextblock/boundsrect(forcontentrect:in:textcontainer:characterrange:).md)

### Drawing colors and decorations

- [drawBackground(withFrame:in:characterRange:layoutManager:)](appkit/nstextblock/drawbackground(withframe:in:characterrange:layoutmanager:).md)

### Initializers

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

### Instance Methods

- [borderColor(for:)](appkit/nstextblock/bordercolor(for:)-273pl.md)
- [borderColor(for:)](appkit/nstextblock/bordercolor(for:)-5m8cr.md)
- [setBorderColor(_:rectEdge:)](appkit/nstextblock/setbordercolor(_:rectedge:).md)
- [setWidth(_:type:for:rectEdge:)](appkit/nstextblock/setwidth(_:type:for:rectedge:).md)
- [width(for:rectEdge:)](appkit/nstextblock/width(for:rectedge:).md)
- [widthValueType(for:rectEdge:)](appkit/nstextblock/widthvaluetype(for:rectedge:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [NSTextTable](appkit/nstexttable.md)
- [NSTextTableBlock](appkit/nstexttableblock.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Formatting and attributes

- [NSParagraphStyle](appkit/nsparagraphstyle.md)
- [NSMutableParagraphStyle](appkit/nsmutableparagraphstyle.md)
- [NSTextTab](appkit/nstexttab.md)
- [NSTextList](appkit/nstextlist.md)
- [NSTextTable](appkit/nstexttable.md)
- [NSTextTableBlock](appkit/nstexttableblock.md)
