<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextAttachmentLayout",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextAttachmentLayout"
  },
  "title" : "NSTextAttachmentLayout"
}
-->

# NSTextAttachmentLayout

A set of methods that defines the interface to attachment objects from a text layout manager.

```
protocol NSTextAttachmentLayout : NSObjectProtocol
```

## Overview

`The NSTextAttachmentLayout` protocol is the interface for working with attachment objects with an [`NSTextAttachmentViewProvider`](/documentation/AppKit/NSTextAttachmentViewProvider) using a [`NSTextLayoutManager`](/documentation/AppKit/NSTextLayoutManager) in macOS 12 and iOS 15 and later.

## Topics

### Determining the characteristics of an attachment

[`func attachmentBounds(for: [NSAttributedString.Key : Any], location: any NSTextLocation, textContainer: NSTextContainer?, proposedLineFragment: CGRect, position: CGPoint) -> CGRect`](/documentation/AppKit/NSTextAttachmentLayout/attachmentBounds(for:location:textContainer:proposedLineFragment:position:))

Returns the layout bounds of the attachment you specify.

[`func image(for: CGRect, attributes: [NSAttributedString.Key : Any], location: any NSTextLocation, textContainer: NSTextContainer?) -> NSImage?`](/documentation/AppKit/NSTextAttachmentLayout/image(for:attributes:location:textContainer:))

Returns the image object rendered at the bounds and inside the text container you specify.

[`func viewProvider(for: NSView?, location: any NSTextLocation, textContainer: NSTextContainer?) -> NSTextAttachmentViewProvider?`](/documentation/AppKit/NSTextAttachmentLayout/viewProvider(for:location:textContainer:))

Returns the text attachment view provider corresponding to the file type.

## Relationships

### Conforming Types

[`NSTextAttachment`](/documentation/AppKit/NSTextAttachment)

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

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)