<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextAttachmentLayout/attachmentBounds(for:location:textContainer:proposedLineFragment:position:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextAttachmentLayout(im)attachmentBoundsForAttributes:location:textContainer:proposedLineFragment:position:"
  },
  "title" : "attachmentBounds(for:location:textContainer:proposedLineFragment:position:)"
}
-->

# attachmentBounds(for:location:textContainer:proposedLineFragment:position:)

Returns the layout bounds of the attachment you specify.

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

## Parameters

`attributes`

A dictionary of <doc://com.apple.documentation/documentation/Foundation/NSAttributedString/Key> attributes.

`location`

An [`NSTextLocation`](/documentation/AppKit/NSTextLocation) that indicates that start of the string.

`textContainer`

The [`NSTextContainer`](/documentation/AppKit/NSTextContainer) that contains the source text.

`proposedLineFragment`

A <doc://com.apple.documentation/documentation/CoreFoundation/CGRect> that describes the boundaries of the line fragment.

`position`

A <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint> inside `proposedLineFragment`.

## Return Value

Returns a <doc://com.apple.documentation/documentation/CoreFoundation/CGRect> that describes the boundaries of the attachment, or `CGRectZero.`

## Discussion

The framework interprets the bounds origin to match `position` inside `proposedLineFragment`. The default [`NSTextAttachment`](/documentation/AppKit/NSTextAttachment) implementation returns bounds if the value isn’t equivalent to <doc://com.apple.documentation/documentation/CoreGraphics/CGRectZero>; otherwise, it derives the bounds value from `image.size`. Conforming objects can implement more sophisticated logic for negotiating the frame size based on the available container space and proposed line fragment rectangle.

---

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)