<!--
{
  "availability" : [
    "macOS: 10.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/boundingRect(with:options:attributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)boundingRectWithSize:options:attributes:"
  },
  "title" : "boundingRect(with:options:attributes:)"
}
-->

# boundingRect(with:options:attributes:)

Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics, within the specified rectangle in the current graphics context.

```
func boundingRect(with size: NSSize, options: NSString.DrawingOptions = [], attributes: [NSAttributedString.Key : Any]? = nil) -> NSRect
```

## Parameters

`size`

The size of the rectangle to draw in.

`options`

String drawing options.

`attributes`

A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an `NSAttributedString` object, but in the case of `NSString` objects, the attributes apply to the entire string, rather than ranges within the string.

## Return Value

The bounding rect for the receiver drawn using the given options and display characteristics. The rect origin returned from this method is the first glyph origin.

## Discussion

This method works in single-line, baseline rendering configuration by default. If the string drawing option `NSStringDrawingUsesLineFragmentOrigin` is specified, the method behaves in multiline configuration.

---

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)