iosuitextviewcore-textnsattributedstringuitextinput

Writing direction of String


Scenario: The user can change the Keyboard language dynamically and enter text into UITextView.

Issue: If the user changes the keyboard language to Arabic and enters text, the text is in Right to Left direction.

Is there a way in which I can determine the writing Direction. Either from UITextView or The Entered Text or Some magic from the Keyboard

Please help me solve this.

Thanks, Roshit

PS: The TextAllignment of UITextView doesnot do the magic..

EDIT: I also convert the NSString from the Textfield into an NSAttributedString and draw Using CoreText. Can I by any chance get the writing direction in this scenario (NSAttributedString or CoreText)


Solution

  • Take a look at the baseWritingDirectionForPosition:inDirection: method of the UITextInput protocol.

    Both UITextView and UITextField implement the UITextInput protocol.