I am using Arabic string and I want to justify it inside UITextView
.
I am retrieving incoming attributingString in the textView and enumerate the NSParagraphStyleAttributeName
to edit it like this :
NSMutableAttributedString * mstring = [[NSMutableAttributedString alloc] initWithAttributedString:_textView.attributedText];
[_textView.attributedText enumerateAttribute:NSParagraphStyleAttributeName inRange:NSMakeRange(0, _textView.attributedText.length) options:0
usingBlock:^(id value, NSRange range, BOOL *stop) {
NSMutableParagraphStyle * paragraphStyle = (NSMutableParagraphStyle *)value;
if (paragraphStyle.alignment == NSTextAlignmentRight) {
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentJustified;
paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft;
[mstring addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
[self.textView setAttributedText:mstring];
}
}];
I found that, if the attributed string is Arabic, the application crashed, but if it is English, it is working normally.
Any ideas to solve this problem?