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

# NSTextBlock

An object that defines the size, spacing, and appearance of a block of text in an attributed string.

## Declaration

```swift
class NSTextBlock
```

## Mentioned in

Adding tables to attributed strings in UIKit

## Overview

Overview A text block lets you control how a paragraph looks and where it sits — you can configure its content dimensions, margin, border, padding, and colors. You create a text block, configure its properties, then assign it to a paragraph by setting the textBlocks property on an NSMutableParagraphStyle and applying that style to a range in an NSMutableAttributedString. To represent a cell inside a table, use NSTextTableBlock instead. Understand content dimensions Each text block has three layers around its content: padding, border, and margin. You can configure the width of each layer per edge using setWidth(_:type:for:rectEdge:), or set all edges at once using setWidth(_:type:for:). Use NSTextBlock.Dimension to set the content area’s width, height, and minimum or maximum constraints. Use NSTextBlock.ValueType to specify whether a dimension is an absolute point value or a percentage. Configure visual appearance Set a background color using backgroundColor. Configure border colors per edge using setBorderColor(_:for:), or apply a single color to all four edges at once using setBorderColor(_:).

## Topics

### Initializing a text block

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

### Setting content dimensions

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

### Setting layer widths

- [setWidth(_:type:for:)](uikit/nstextblock/setwidth(_:type:for:).md)
- [setWidth(_:type:for:rectEdge:)](uikit/nstextblock/setwidth(_:type:for:rectedge:).md)
- [width(for:rectEdge:)](uikit/nstextblock/width(for:rectedge:).md)
- [widthValueType(for:rectEdge:)](uikit/nstextblock/widthvaluetype(for:rectedge:).md)

### Configuring appearance

- [verticalAlignment](uikit/nstextblock/verticalalignment-swift.property.md)
- [backgroundColor](uikit/nstextblock/backgroundcolor.md)
- [setBorderColor(_:)](uikit/nstextblock/setbordercolor(_:).md)
- [setBorderColor(_:rectEdge:)](uikit/nstextblock/setbordercolor(_:rectedge:).md)
- [borderColor(for:)](uikit/nstextblock/bordercolor(for:).md)

### Supporting types

- [NSTextBlock.ValueType](uikit/nstextblock/valuetype.md)
- [NSTextBlock.Dimension](uikit/nstextblock/dimension.md)
- [NSTextBlock.Layer](uikit/nstextblock/layer.md)
- [NSTextBlock.VerticalAlignment](uikit/nstextblock/verticalalignment-swift.enum.md)

## Relationships

### Inherits From

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

### Inherited By

- [NSTextTable](uikit/nstexttable.md)
- [NSTextTableBlock](uikit/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

### Tables

- [Adding tables to attributed strings in UIKit](uikit/adding-tables-to-attributed-strings.md)
- [NSTextTable](uikit/nstexttable.md)
- [NSTextTableBlock](uikit/nstexttableblock.md)
