<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/size(withAttributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)sizeWithAttributes:"
  },
  "title" : "size(withAttributes:)"
}
-->

# size(withAttributes:)

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

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

The bounding box size the receiver occupies when drawn with the specified attributes.

## 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 <doc://com.apple.documentation/documentation/kernel/1557272-ceil> function.

---

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)