UILabel 文本行设置为方形排列 iOS

UILabel Text line set as square shape arrange iOS

我想标签文本排列在标签文本行的方形视图格式上,标签有一些短字,有些比标签文本的其他字大所以请看这个演示图片Sqaure shape Image

尝试使用 NSAttributedString 希望支持多种字体和文本大小并使用 \n 到 return 到下一行。

    NSDictionary *italicAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:16], NSForegroundColorAttributeName : [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]};

    NSDictionary *defaultAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Medium" size:16], NSForegroundColorAttributeName : [UIColor blackColor]};

    NSDictionary *arrowAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"AlNile-Bold" size:20], NSForegroundColorAttributeName : [UIColor grayColor]};


    NSMutableAttributedString *labelText = [[NSMutableAttributedString alloc] init];

    NSAttributedString *from = [[NSAttributedString alloc] initWithString:@"From: " attributes:italicAttrs];

    NSAttributedString *content = [[NSAttributedString alloc] initWithString:@"Me\n" attributes:defaultAttrs];

    NSAttributedString *arrow = [[NSAttributedString alloc] initWithString:@"Ok" attributes:arrowAttrs];


    [labelText appendAttributedString:from];
    [labelText appendAttributedString:content];
    [labelText appendAttributedString:arrow];