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

# draw(with:options:attributes:context:)

Draws the attributed string in the specified bounding rectangle using the provided options.

```
func draw(with rect: CGRect, options: NSStringDrawingOptions = [], attributes: [NSAttributedString.Key : Any]? = nil, context: NSStringDrawingContext?)
```

## Parameters

`rect`

The bounding rectangle in which to draw the string.

`options`

Additional drawing options to apply to the string during rendering. For a list of possible values, see <doc://com.apple.documentation/documentation/UIKit/NSStringDrawingOptions>.

`attributes`

The text attributes with which to draw 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.

`context`

A context object with information about how to adjust the font tracking and scaling information. On return, the specified object contains information about the actual values used to render the string. This parameter may be `nil`.

## Discussion

This method draws as much of the string as it can inside the specified rectangle, wrapping the string text as needed to make it fit. If the string is too big to fit completely inside the rectangle, the method scales the font or adjusts the letter spacing to make the string fit within the given bounds.

If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point. To correctly draw and size multi-line text, pass <doc://com.apple.documentation/documentation/UIKit/NSStringDrawingOptions/usesLineFragmentOrigin> in the options parameter.

### Special Considerations

This method uses the baseline origin by default.

If <doc://com.apple.documentation/documentation/UIKit/NSStringDrawingOptions/usesLineFragmentOrigin> is not specified, the rectangle’s height will be ignored and the operation considered to be single-line rendering.

---

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)