<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextLayoutManagerDelegate/textLayoutManager(_:textLayoutFragmentFor:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextLayoutManagerDelegate(im)textLayoutManager:textLayoutFragmentForLocation:inTextElement:"
  },
  "title" : "textLayoutManager(_:textLayoutFragmentFor:in:)"
}
-->

# textLayoutManager(_:textLayoutFragmentFor:in:)

Returns a text layout fragment for the specified location in the text element.

```
optional func textLayoutManager(_ textLayoutManager: NSTextLayoutManager, textLayoutFragmentFor location: any NSTextLocation, in textElement: NSTextElement) -> NSTextLayoutFragment
```

## Parameters

`textLayoutManager`

The text layout manager sending the message.

`location`

The document location.

`textElement`

The text element containing the location.

## Return Value

A layout fragment for the location, or `nil` to use the default.

## Discussion

The delegate can provide an [`NSTextLayoutFragment`](/documentation/AppKit/NSTextLayoutFragment) specialized for an
[`NSTextElement`](/documentation/AppKit/NSTextElement) subclass targeted for the rendering surface.

The method the framework calls to give the delegate an opportunity to return a custom text layout fragment.

## Discussion

Use this to provide an [`NSTextLayoutFragment`](/documentation/AppKit/NSTextLayoutFragment) specialized for an [`NSTextElement`](/documentation/AppKit/NSTextElement) subclass targeted for the rendering surface.

---

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)