使用UITextView和NSMutableAttributedStringalignment文本

我试图把一个UITextViewNSMutableAttributedString合理的文本, NSMutableAttributedString由不同的NSAttributedString组成,因为我需要粗体和常规字体,所以我追加不同的NSString ,这是我的NSMutableAttributedString

 NSAttributedString *one = [[NSAttributedString alloc] initWithString:@"abc" attributes:boldDict]; NSAttributedString *two = [[NSAttributedString alloc] initWithString:@" def" attributes:regularDict]; NSAttributedString *three = [[NSAttributedString alloc] initWithString:@" ghi" attributes:boldDict]; NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:one]; [string appendAttributedString:two]; [string appendAttributedString:three]; 

我试过这个:

 [self.text_view setTextAlignment:NSTextAlignmentJustified] 

和这个:

 NSMutableParagraphStyle *paragraphStyles = [[NSMutableParagraphStyle alloc] init]; paragraphStyles.alignment = NSTextAlignmentJustified; Dictionary *attributes = @{NSParagraphStyleAttributeName: paragraphStyles}; 

并将其应用于NSMutableAttributedString,但都不起作用。 我怎么办?

我通过为NSAttributedString指定透明背景色来解决同样的问题。

看起来像UILabel代码中的一个错误,它应该像NSString那样呈现简单的NSAttributedString。

Xamarin.iOS例子:

 var paragraphStyle = new NSMutableParagraphStyle(); paragraphStyle.Alignment = UITextAlignment.Justified; var attributedText = new NSAttributedString(simpleString, paragraphStyle: paragraphStyle, backgroundColor: Color.Transparent.ToUIColor()); myLabel.AttributedText = attributedText;