美文网首页
iOS 实现UIlabel的两端对齐效果

iOS 实现UIlabel的两端对齐效果

作者: fairy_happy | 来源:发表于2017-09-25 18:56 被阅读19次

    未进行两端对齐格式时,文字显得参差不齐

    对齐前效果

    设置两端对齐后的效果

    对齐效果

    废话不多说,直接上代码

     NSMutableAttributedString *mutaString = [[NSMutableAttributedString alloc]initWithString:model.describestring];
        NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init];
        paraStyle.alignment = NSTextAlignmentJustified;//两端对齐
        paraStyle.paragraphSpacing = 14.0;//行后间距
        NSDictionary *dic = @{
                              NSForegroundColorAttributeName:[UIColor blackColor],
                              NSFontAttributeName:[UIFont systemFontOfSize:14],
                              NSParagraphStyleAttributeName:paraStyle,
                              NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone]
                              };
        [mutaString setAttributes:dic range:NSMakeRange(0, mutaString.length)];
        _describeLabel.attributedText = mutaString;
    

    相关文章

      网友评论

          本文标题:iOS 实现UIlabel的两端对齐效果

          本文链接:https://www.haomeiwen.com/subject/lpvdextx.html