<!--
{
  "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/NSTextAttachmentViewProvider",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextAttachmentViewProvider"
  },
  "title" : "NSTextAttachmentViewProvider"
}
-->

# NSTextAttachmentViewProvider

A container object that associates a text attachment at a particular document location with a view object.

```
class NSTextAttachmentViewProvider
```

## Overview

Use `NSTextAttachmentViewProvider` when you need to represent document locations in terms of an [`NSTextLocation`](/documentation/UIKit/NSTextLocation) or an [`NSTextRange`](/documentation/UIKit/NSTextRange) or you want to support view-based text attachments. The view provider controls the view placement and layout without requiring view classes to be aware of the text attachment coordination using a [`NSTextLayoutManager`](/documentation/UIKit/NSTextLayoutManager) in macOS 12 or iOS 15 and later.

## Topics

### Initializing a text attachment view

[`-  initWithTextAttachment:parentView:textLayoutManager:location:`](/documentation/UIKit/NSTextAttachmentViewProvider/init(textAttachment:parentView:textLayoutManager:location:))

Creates a new text attachment view whose content starts at the location you provide.

### Defining the contents

[`location`](/documentation/UIKit/NSTextAttachmentViewProvider/location)

The location that indicates the start of the text attachment.

[`textAttachment`](/documentation/UIKit/NSTextAttachmentViewProvider/textAttachment)

The text attachment for this view.

[`textLayoutManager`](/documentation/UIKit/NSTextAttachmentViewProvider/textLayoutManager)

The text layout manager for this view.

[`tracksTextAttachmentViewBounds`](/documentation/UIKit/NSTextAttachmentViewProvider/tracksTextAttachmentViewBounds)

A Boolean value that determines the text attachment’s bounds policy.

[`view`](/documentation/UIKit/NSTextAttachmentViewProvider/view)

The text attachment’s view.

### Defining a custom view hierarchy

[`-  loadView`](/documentation/UIKit/NSTextAttachmentViewProvider/loadView())

Draws the custom view hierarchy that text attachment view subclasses implement.

### Determining the Attachment’s Bounds

[`-  attachmentBoundsForAttributes:location:textContainer:proposedLineFragment:position:`](/documentation/UIKit/NSTextAttachmentViewProvider/attachmentBounds(for:location:textContainer:proposedLineFragment:position:))

Returns the layout bounds for an attachment at a specific text location that contains the text attributes you specify.

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`Hashable`](/documentation/Swift/Hashable)

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

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)