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

# NSTextLayoutFragment

A class that represents the layout fragment typically corresponding to a rendering surface, such as a layer or view subclass.

```
class NSTextLayoutFragment
```

## Topics

### Creating a layout fragment

[`init(coder:)`](/documentation/UIKit/NSTextLayoutFragment/init(coder:))

Creates a new layout fragment with the coder you provide.

[`init(textElement:range:)`](/documentation/UIKit/NSTextLayoutFragment/init(textElement:range:))

Create a new layout fragment using the provided text element and range.

### Getting line fragments

[`textLineFragments`](/documentation/UIKit/NSTextLayoutFragment/textLineFragments)

An array of text line fragments.

[`NSTextLayoutFragment.EnumerationOptions`](/documentation/UIKit/NSTextLayoutFragment/EnumerationOptions)

Values that describe options for enumerating text layout fragments.

[`textLineFragment(for:isUpstreamAffinity:)`](/documentation/UIKit/NSTextLayoutFragment/textLineFragment(for:isUpstreamAffinity:))

Returns a text line fragment from a specific text location in the document.

[`textLineFragment(forVerticalOffset:requiresExactMatch:)`](/documentation/UIKit/NSTextLayoutFragment/textLineFragment(forVerticalOffset:requiresExactMatch:))

Returns the text line fragment for the vertical offset you provide, or the closest text line fragment beyond the vertical offset.

### Getting element information

[`state`](/documentation/UIKit/NSTextLayoutFragment/state-swift.property)

The layout information state.

[`NSTextLayoutFragment.State`](/documentation/UIKit/NSTextLayoutFragment/State-swift.enum)

Values that describe the possible layout states.

[`rangeInElement`](/documentation/UIKit/NSTextLayoutFragment/rangeInElement)

The range inside the text element relative to the document origin.

[`textElement`](/documentation/UIKit/NSTextLayoutFragment/textElement)

The parent text element.

### Accessing the layout manager

[`textLayoutManager`](/documentation/UIKit/NSTextLayoutFragment/textLayoutManager)

The layout manager for this text layout fragment.

### Drawing the fragment and attachments

[`layoutFragmentFrame`](/documentation/UIKit/NSTextLayoutFragment/layoutFragmentFrame)

The rectangle the framework uses for tiling the layout fragment inside the target layout coordinate system.

[`renderingSurfaceBounds`](/documentation/UIKit/NSTextLayoutFragment/renderingSurfaceBounds)

The bounds defining the area required for rendering the contents.

[`draw(at:in:)`](/documentation/UIKit/NSTextLayoutFragment/draw(at:in:))

Renders the visual representation of this element in the specified graphics context.

[`invalidateLayout()`](/documentation/UIKit/NSTextLayoutFragment/invalidateLayout())

Invalidates any layout information associated with the text layout fragment.

[`textAttachmentViewProviders`](/documentation/UIKit/NSTextLayoutFragment/textAttachmentViewProviders)

The attachment view provider associated with the text layout fragment.

[`frameForTextAttachment(at:)`](/documentation/UIKit/NSTextLayoutFragment/frameForTextAttachment(at:))

Returns the frame in the text layout fragment coordinate system for the attachment at the location you specify.

### Accessing the layout processing queue

[`layoutQueue`](/documentation/UIKit/NSTextLayoutFragment/layoutQueue)

The queue on which the framework dispatches layout operations.

### Defining margins and padding

[`bottomMargin`](/documentation/UIKit/NSTextLayoutFragment/bottomMargin)

The amount of space reserved during paragraph layout between the bottom of the last line in the paragraph and the bottom of the text layout fragment.

[`leadingPadding`](/documentation/UIKit/NSTextLayoutFragment/leadingPadding)

The amount of margin space reserved during paragraph layout between the leading edge of the text layout fragment and the start of the lines in the paragraph.

[`topMargin`](/documentation/UIKit/NSTextLayoutFragment/topMargin)

The amount of space reserved during paragraph layout between the top of the text layout fragment and the top of the first line in the paragraph.

[`trailingPadding`](/documentation/UIKit/NSTextLayoutFragment/trailingPadding)

The amount of margin space reserved during paragraph layout between the end of the lines in the paragraph and the trailing edge of the text layout fragment.



---

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)