4

I have a textview. I am getting arabic text from server to be shown in the textview. I need to justify the text. The text is justified with NSTextAlignmentJustified. For right to left languages like arabic, the last line in paragraph must be right aligned. But it is left aligned. Please explain how to make the last line right aligned.

Thanks for your help in advance

Paebbels
  • 15,573
  • 13
  • 70
  • 139
Alfred
  • 136
  • 8
  • I doubt NSTextAlginment is the right thing here to use (except `NSNaturalTextAlignment`)! You should instead take a look at the apple cods regarding [how to handle right-to-left languages](https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/SupportingRight-To-LeftLanguages/SupportingRight-To-LeftLanguages.html) – luk2302 May 10 '15 at 17:36
  • why don't you use NSTextAlignmentRight? – Hossam Ghareeb May 10 '15 at 17:38
  • It is a requirement from the client to justify. Thanks for looking into this. – Alfred May 11 '15 at 07:39

1 Answers1

-1
UITextPosition *beginning = self.textview.beginningOfDocument;
UITextPosition *start = [self.textview positionFromPosition:beginning   offset:0];
UITextPosition *end = [self.textview positionFromPosition:start offset: [self.textview.text length]];
UITextRange *textRange = [self.textview textRangeFromPosition:start toPosition:end];
[self.textview setBaseWritingDirection:UITextWritingDirectionRightToLeft forRange:textRange];

self.textview.textAlignment = NSTextAlignmentJustified;

This is how I did it in my app. I hope it will work for you.

ZygD
  • 22,092
  • 39
  • 79
  • 102
MuslimDev
  • 1
  • 1
  • You should never need to set the writing direction of a range of text explicitly. Forcing it to be RTL will among other things break LTR text. – lensovet Oct 19 '15 at 10:23