2

I support both Left-to-Right and Right-to-Left in my application. How can I detect text direction in my UITextView/UITextField?

  • I can't use device's locale because user can have multiple keyboards with languages with different read/write directions.
  • I suppose UITextInputTraits is also no use because Apple's documentation said that controls only additional keyboard buttons and not the ones with letters.

Any ideas?

Paebbels
  • 15,573
  • 13
  • 70
  • 139
Maria
  • 755
  • 1
  • 11
  • 29
  • 1
    Possible duplicate of [How to know the direction of the text?](https://stackoverflow.com/questions/11305791/how-to-know-the-direction-of-the-text) – Tamás Sengel Feb 13 '18 at 14:26

1 Answers1

1

Take a look at the documentation on UITextInput: The below method will return the direction of the text.

func baseWritingDirection(for position: UITextPosition, in direction: UITextStorageDirection) -> UITextWritingDirection {
    <#code#>
}

Official documentation: https://developer.apple.com/documentation/uikit/uitextinput/1614502-basewritingdirection

valosip
  • 3,167
  • 1
  • 14
  • 26