I use the Arabic string, and I want to justify it inside UITextView.
I get the incoming String attribute in the textView and list NSParagraphStyleAttributeNameto edit it as follows:
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 attribute string is Arabic, the application crashed, but if it is English, it works fine.
Any ideas to solve this problem?
source
share