<!--
{
  "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/characterRange(byExtending:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextInput(im)characterRangeByExtendingPosition:inDirection:"
  },
  "title" : "characterRange(byExtending:in:)"
}
-->

# characterRange(byExtending:in:)

Returns a text range from a specified text position to its farthest extent in a certain direction of layout.

```
func characterRange(byExtending position: UITextPosition, in direction: UITextLayoutDirection) -> UITextRange?
```

## Parameters

`position`

A text-position object that identifies a location in a document.

`direction`

A constant that indicates a direction of layout (right, left, up, down).

## Return Value

A text-range object that represents the distance from `position` to the farthest extent in `direction`.

## Discussion

---

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)