---
title: "boundingRect(with:options:attributes:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/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.

## Declaration

```swift
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

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

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.

## See Also

### Deprecated

- [string(withCString:)](foundation/nsstring/string(withcstring:).md)
- [init(CString:)](foundation/nsstring/init(cstring:)-vkuo.md)
- [string(withCString:length:)](foundation/nsstring/string(withcstring:length:).md)
- [init(CString:length:)](foundation/nsstring/init(cstring:length:)-5ure3.md)
- [init(CStringNoCopy:length:freeWhenDone:)](foundation/nsstring/init(cstringnocopy:length:freewhendone:)-86dm2.md)
- [string(withContentsOfFile:)](foundation/nsstring/string(withcontentsoffile:).md)
- [init(contentsOfFile:)](foundation/nsstring/init(contentsoffile:).md)
- [string(withContentsOf:)](foundation/nsstring/string(withcontentsof:).md)
- [init(contentsOfURL:)](foundation/nsstring/init(contentsofurl:).md)
- [write(toFile:atomically:)](foundation/nsstring/write(tofile:atomically:).md)
- [write(to:atomically:)](foundation/nsstring/write(to:atomically:).md)
- [getCharacters(_:)](foundation/nsstring/getcharacters(_:).md)
- [cString()](foundation/nsstring/cstring().md)
- [lossyCString()](foundation/nsstring/lossycstring().md)
- [cStringLength()](foundation/nsstring/cstringlength().md)
