I'm trying to put a justified text for a UITextView
with NSMutableAttributedString
, the NSMutableAttributedString
is composed of different NSAttributedString
because I need bold and regular font, so I append different NSString
, this is my 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];
I have tried this:
[self.text_view setTextAlignment:NSTextAlignmentJustified]
and this:
NSMutableParagraphStyle *paragraphStyles = [[NSMutableParagraphStyle alloc] init];
paragraphStyles.alignment = NSTextAlignmentJustified;
Dictionary *attributes = @{NSParagraphStyleAttributeName: paragraphStyles};
and apply this to NSMutableAttributedString, but neither works. how i can do?