---
title: "textLayoutManager(_:textLayoutFragmentFor:in:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextlayoutmanagerdelegate/textlayoutmanager(_:textlayoutfragmentfor:in:)"
---

# textLayoutManager(_:textLayoutFragmentFor:in:)

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

## Declaration

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

## Parameters

- `textLayoutManager`: The text layout manager.
- `location`: The doc://com.apple.appkit/documentation/AppKit/NSTextLocation of the link in the text element.
- `textElement`: The doc://com.apple.appkit/documentation/AppKit/NSTextElement that the method could return a custom doc://com.apple.appkit/documentation/AppKit/NSTextLayoutFragment from.

## Return Value

Return Value An NSTextLayoutFragment.

## Discussion

Discussion Use this to provide an NSTextLayoutFragment specialized for an NSTextElement subclass targeted for the rendering surface.

## See Also

### Responding to layout changes

- [textLayoutManager(_:renderingAttributesForLink:at:defaultAttributes:)](appkit/nstextlayoutmanagerdelegate/textlayoutmanager(_:renderingattributesforlink:at:defaultattributes:).md)
- [textLayoutManager(_:shouldBreakLineBefore:hyphenating:)](appkit/nstextlayoutmanagerdelegate/textlayoutmanager(_:shouldbreaklinebefore:hyphenating:).md)
