---
title: "size(withAttributes:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/size(withattributes:)"
---

# size(withAttributes:)

Returns the bounding box size the receiver occupies when drawn with the given attributes.

## Declaration

```swift
func size(withAttributes attrs: [NSAttributedString.Key : Any]? = nil) -> CGSize
```

## Parameters

- `attrs`: 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 box size the receiver occupies when drawn with the specified attributes.

## Discussion

Discussion This method returns fractional sizes; to use a returned size to size views, you must raise its value to the nearest higher integer using the ceil function.

## See Also

### Sizing and Drawing Strings

- [draw(at:withAttributes:)](foundation/nsstring/draw(at:withattributes:).md)
- [draw(in:withAttributes:)](foundation/nsstring/draw(in:withattributes:).md)
- [draw(with:options:attributes:context:)](foundation/nsstring/draw(with:options:attributes:context:).md)
- [boundingRect(with:options:attributes:context:)](foundation/nsstring/boundingrect(with:options:attributes:context:).md)
- [variantFittingPresentationWidth(_:)](foundation/nsstring/variantfittingpresentationwidth(_:).md)
- [NSStringDrawingOptions](uikit/nsstringdrawingoptions.md)
