4

我正在使用阿拉伯字符串,我想在里面证明它是合理的UITextView

我在 textView 中检索传入的 attributingString 并枚举NSParagraphStyleAttributeName来编辑它,如下所示:

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];
                                      }


}];

我发现,如果属性字符串是阿拉伯语,则应用程序崩溃,但如果是英语,它可以正常工作。

有什么想法可以解决这个问题吗?

4

0 回答 0