<!--
{
  "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/NSTextLayoutManagerDelegate/textLayoutManager(_:textLayoutFragmentFor:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextLayoutManagerDelegate(im)textLayoutManager:textLayoutFragmentForLocation:inTextElement:"
  },
  "title" : "textLayoutManager(_:textLayoutFragmentFor:in:)"
}
-->

# textLayoutManager(_:textLayoutFragmentFor:in:)

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

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

## Parameters

`textLayoutManager`

The text layout manager.

`location`

The [`NSTextLocation`](/documentation/UIKit/NSTextLocation) of the link in the text element.

`textElement`

The [`NSTextElement`](/documentation/UIKit/NSTextElement) that the method could return a custom [`NSTextLayoutFragment`](/documentation/UIKit/NSTextLayoutFragment) from.

## Return Value

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

## Discussion

Use this to provide an [`NSTextLayoutFragment`](/documentation/UIKit/NSTextLayoutFragment) specialized for an [`NSTextElement`](/documentation/UIKit/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)