<!--
{
  "availability" : [
    "iOS: 3.2.0 -",
    "iPadOS: 3.2.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextInput/caretRect(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextInput(im)caretRectForPosition:"
  },
  "title" : "caretRect(for:)"
}
-->

# caretRect(for:)

Returns a rectangle to draw the caret at a specified insertion point.

```
func caretRect(for position: UITextPosition) -> CGRect
```

## Parameters

`position`

An object that identifies a location in a text input area.

## Return Value

A rectangle that defines the area for drawing the caret.

## Discussion

The system uses this value to calculate the length of the beam—the vertical line representing the pointer—when using a trackpad to interact with a text input area. You must implement this method even if text never becomes editable, and an insertion point caret never appears.

## See Also

[`firstRect(for:)`](/documentation/UIKit/UITextInput/firstRect(for:))

Returns the first rectangle that encloses a range of text in a document.

[`UIPointerShape.verticalBeam(length:)`](/documentation/UIKit/UIPointerShape-swift.enum/verticalBeam(length:))

The pointer morphs into a vertical beam using the specified length.



---

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)