<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextBlock",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextBlock"
  },
  "title" : "NSTextBlock"
}
-->

# NSTextBlock

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

```
class NSTextBlock
```

## 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`](/documentation/UIKit/NSParagraphStyle/textBlocks) property on an [`NSMutableParagraphStyle`](/documentation/UIKit/NSMutableParagraphStyle) and applying that style to a range in an `NSMutableAttributedString`. To represent a cell inside a table, use [`NSTextTableBlock`](/documentation/UIKit/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:)`](/documentation/UIKit/NSTextBlock/setWidth(_:type:for:rectEdge:)), or set all edges at once using [`setWidth(_:type:for:)`](/documentation/UIKit/NSTextBlock/setWidth(_:type:for:)). Use [`NSTextBlock.Dimension`](/documentation/UIKit/NSTextBlock/Dimension) to set the content area’s width, height, and minimum or maximum constraints. Use [`NSTextBlock.ValueType`](/documentation/UIKit/NSTextBlock/ValueType) to specify whether a dimension is an absolute point value or a percentage.

### Configure visual appearance

Set a background color using [`backgroundColor`](/documentation/UIKit/NSTextBlock/backgroundColor). Configure border colors per edge using `setBorderColor(_:for:)`, or apply a single color to all four edges at once using [`setBorderColor(_:)`](/documentation/UIKit/NSTextBlock/setBorderColor(_:)).

## Topics

### Initializing a text block

[`-  init`](/documentation/UIKit/NSTextBlock/init())

[`-  initWithCoder:`](/documentation/UIKit/NSTextBlock/init(coder:))

### Setting content dimensions

[`-  setValue:type:forDimension:`](/documentation/UIKit/NSTextBlock/setValue(_:type:for:))

[`-  valueForDimension:`](/documentation/UIKit/NSTextBlock/value(for:))

[`-  valueTypeForDimension:`](/documentation/UIKit/NSTextBlock/valueType(for:))

[`-  setContentWidth:type:`](/documentation/UIKit/NSTextBlock/setContentWidth(_:type:))

[`contentWidth`](/documentation/UIKit/NSTextBlock/contentWidth)

[`contentWidthValueType`](/documentation/UIKit/NSTextBlock/contentWidthValueType)

### Setting layer widths

[`-  setWidth:type:forLayer:`](/documentation/UIKit/NSTextBlock/setWidth(_:type:for:))

[`-  setWidth:type:forLayer:rectEdge:`](/documentation/UIKit/NSTextBlock/setWidth(_:type:for:rectEdge:))

[`-  widthForLayer:rectEdge:`](/documentation/UIKit/NSTextBlock/width(for:rectEdge:))

[`-  widthValueTypeForLayer:rectEdge:`](/documentation/UIKit/NSTextBlock/widthValueType(for:rectEdge:))

### Configuring appearance

[`verticalAlignment`](/documentation/UIKit/NSTextBlock/verticalAlignment-swift.property)

[`backgroundColor`](/documentation/UIKit/NSTextBlock/backgroundColor)

[`-  setBorderColor:`](/documentation/UIKit/NSTextBlock/setBorderColor(_:))

[`-  setBorderColor:rectEdge:`](/documentation/UIKit/NSTextBlock/setBorderColor(_:rectEdge:))

[`-  borderColorForRectEdge:`](/documentation/UIKit/NSTextBlock/borderColor(for:))

### Supporting types

[`ValueType`](/documentation/UIKit/NSTextBlock/ValueType)

[`Dimension`](/documentation/UIKit/NSTextBlock/Dimension)

[`Layer`](/documentation/UIKit/NSTextBlock/Layer)

[`VerticalAlignment`](/documentation/UIKit/NSTextBlock/VerticalAlignment-swift.enum)

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

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

### Inherited By

[`NSTextTable`](/documentation/UIKit/NSTextTable)

[`NSTextTableBlock`](/documentation/UIKit/NSTextTableBlock)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)