How to right-justify UILabel text?

前端 未结 6 1118
悲哀的现实
悲哀的现实 2021-02-14 12:38

How to right-justify UILabel text?

thanks

6条回答
  •  情歌与酒
    2021-02-14 13:10

    Here is: be careful if full justify needs to be applied, firstLineIndent should not be zero.

    NSMutableParagraphStyle* paragraph = [[NSMutableParagraphStyle alloc] init];
    paragraph.alignment = NSTextAlignmentJustified;
    paragraph.baseWritingDirection = NSWritingDirectionRightToLeft;
    paragraph.firstLineHeadIndent = 1.0;
    NSDictionary* attributes = @{
                                 NSForegroundColorAttributeName: [UIColor colorWithRed:0.2 green:0.239 blue:0.451 alpha:1],NSParagraphStyleAttributeName: paragraph};
    NSString* txt = @"your long text";
    NSAttributedString* aString = [[NSAttributedString alloc] initWithString: txt attributes: attributes];
    

提交回复
热议问题