ios label 设置 文本 左右两端对齐

swift
        //设置文字两端对齐
        let attri = NSMutableAttributedString(string: label.text!)
        let para = NSMutableParagraphStyle.init()
        para.alignment = .justified
        
        attri.addAttributes([ .paragraphStyle: para , .underlineStyle :  NSNumber.init(value: Int8(NSUnderlineStyle.styleNone.rawValue))
            ], range: NSMakeRange(0, attri.length))
        label.attributedText = attri

        

    oc中 

         NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:label.text];
         NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc]init];
         //设置文字两端对齐
         para.alignment = NSTextAlignmentJustified;
         NSDictionary *dic = @{
         //
         NSParagraphStyleAttributeName: para,
         NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleNone],
         };
         [attri setAttributes:dic range:NSMakeRange(0, attri.length)];
         label.attributedText = attri;
         ```

你可能感兴趣的:(ios label 设置 文本 左右两端对齐)