emenegro
emenegro

Reputation: 6971

How to know the direction of the text?

I need to know the direction of a text depending on the language of the keyboard when typing in a UITextView. For example, if the user is typing in english, then the direction will be "left to right" and if the user is typing in arabic, "right to left". I need that value without doubts and avoiding to hardcoding a matching between each language and its text direction.

Is this possible?

Upvotes: 4

Views: 702

Answers (1)

Jonathan Naguin
Jonathan Naguin

Reputation: 14766

Check this out this method from UITextInput Protocol:

- (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction

This returns a constant that represents a writing direction (for example, left-to-right or right-to-left)

UITextView implements such protocol.

Upvotes: 4

Related Questions