修改UILable的属性,包括行间距等。

        NSDictionary* dic1 = [[NSDictionary alloc]initWithObjectsAndKeys:font,NSFontAttributeName,[@"b5b5b5" toUIColor], NSForegroundColorAttributeName,nil];

        NSDictionary* dic2 = [[NSDictionary alloc]initWithObjectsAndKeys:font,NSFontAttributeName, [@"1c66a8" toUIColor], NSForegroundColorAttributeName,nil];

        NSDictionary* dic3 = [[NSDictionary alloc]initWithObjectsAndKeys:font,NSFontAttributeName,[@"b5b5b5" toUIColor], NSForegroundColorAttributeName,nil];

        NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString:text];

        [attrString addAttributes:dic1 range:NSMakeRange(0, 2)];

        [attrString addAttributes:dic2 range:NSMakeRange(2,commentModel.replyUser.length)];

        [attrString addAttributes:dic3 range:NSMakeRange(2+commentModel.replyUser.length,commentModel.parentInfo.content.length+1)];

        NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];

        [paragraphStyle1 setLineSpacing:8];

        [attrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [text length])];

        _replyFlagLable.attributedText = attrString;

原文地址:https://www.cnblogs.com/417460188dy/p/4103173.html