UITextView
我正在尝试为with放置一个合理的文本NSMutableAttributedString
,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,但都不起作用。我该怎么办?