---
title: NSTextLayoutFragment
framework: uikit
role: symbol
role_heading: Class
path: uikit/nstextlayoutfragment
---

# NSTextLayoutFragment

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

## Declaration

```swift
class NSTextLayoutFragment
```

## Topics

### Creating a layout fragment

- [init(coder:)](uikit/nstextlayoutfragment/init(coder:).md)
- [init(textElement:range:)](uikit/nstextlayoutfragment/init(textelement:range:).md)

### Getting line fragments

- [textLineFragments](uikit/nstextlayoutfragment/textlinefragments.md)
- [NSTextLayoutFragment.EnumerationOptions](uikit/nstextlayoutfragment/enumerationoptions.md)
- [textLineFragment(for:isUpstreamAffinity:)](uikit/nstextlayoutfragment/textlinefragment(for:isupstreamaffinity:).md)
- [textLineFragment(forVerticalOffset:requiresExactMatch:)](uikit/nstextlayoutfragment/textlinefragment(forverticaloffset:requiresexactmatch:).md)

### Getting element information

- [state](uikit/nstextlayoutfragment/state-swift.property.md)
- [NSTextLayoutFragment.State](uikit/nstextlayoutfragment/state-swift.enum.md)
- [rangeInElement](uikit/nstextlayoutfragment/rangeinelement.md)
- [textElement](uikit/nstextlayoutfragment/textelement.md)

### Accessing the layout manager

- [textLayoutManager](uikit/nstextlayoutfragment/textlayoutmanager.md)

### Drawing the fragment and attachments

- [layoutFragmentFrame](uikit/nstextlayoutfragment/layoutfragmentframe.md)
- [renderingSurfaceBounds](uikit/nstextlayoutfragment/renderingsurfacebounds.md)
- [draw(at:in:)](uikit/nstextlayoutfragment/draw(at:in:).md)
- [invalidateLayout()](uikit/nstextlayoutfragment/invalidatelayout().md)
- [textAttachmentViewProviders](uikit/nstextlayoutfragment/textattachmentviewproviders.md)
- [frameForTextAttachment(at:)](uikit/nstextlayoutfragment/framefortextattachment(at:).md)

### Accessing the layout processing queue

- [layoutQueue](uikit/nstextlayoutfragment/layoutqueue.md)

### Defining margins and padding

- [bottomMargin](uikit/nstextlayoutfragment/bottommargin.md)
- [leadingPadding](uikit/nstextlayoutfragment/leadingpadding.md)
- [topMargin](uikit/nstextlayoutfragment/topmargin.md)
- [trailingPadding](uikit/nstextlayoutfragment/trailingpadding.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.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)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [NSTextViewportRenderingSurfaceKey](uikit/nstextviewportrenderingsurfacekey.md)

## See Also

### Layout

- [Using TextKit 2 to interact with text](uikit/using-textkit-2-to-interact-with-text.md)
- [Display text with a custom layout](uikit/display-text-with-a-custom-layout.md)
- [Managing viewport layout and attachment reuse in text views](uikit/managing-viewport-layout-and-attachment-reuse-in-a-text-view-subclass.md)
- [NSTextLayoutManager](uikit/nstextlayoutmanager.md)
- [NSTextContainer](uikit/nstextcontainer.md)
- [NSTextLineFragment](uikit/nstextlinefragment.md)
- [NSTextViewportLayoutController](uikit/nstextviewportlayoutcontroller.md)
- [NSTextViewportRenderingSurface](uikit/nstextviewportrenderingsurface.md)
- [NSTextViewportRenderingSurfaceKey](uikit/nstextviewportrenderingsurfacekey.md)
- [NSTextLayoutOrientationProvider](uikit/nstextlayoutorientationprovider.md)
