---
title: NSTextLayoutFragment
framework: appkit
role: symbol
role_heading: Class
path: appkit/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:)](appkit/nstextlayoutfragment/init(coder:).md)
- [init(textElement:range:)](appkit/nstextlayoutfragment/init(textelement:range:).md)

### Getting line fragments

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

### Getting element information

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

### Accessing the layout manager

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

### Drawing the fragment and attachments

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

### Accessing the layout processing queue

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

### Defining margins and padding

- [bottomMargin](appkit/nstextlayoutfragment/bottommargin.md)
- [leadingPadding](appkit/nstextlayoutfragment/leadingpadding.md)
- [topMargin](appkit/nstextlayoutfragment/topmargin.md)
- [trailingPadding](appkit/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](appkit/nstextviewportrenderingsurfacekey.md)

## See Also

### Layout

- [Using TextKit 2 to interact with text](uikit/using-textkit-2-to-interact-with-text.md)
- [NSTextLayoutManager](appkit/nstextlayoutmanager.md)
- [NSTextContainer](appkit/nstextcontainer.md)
- [NSTextLineFragment](appkit/nstextlinefragment.md)
- [NSTextViewportLayoutController](appkit/nstextviewportlayoutcontroller.md)
- [NSTextLayoutOrientationProvider](appkit/nstextlayoutorientationprovider.md)
