height = [self.label.text sizeThatFits:CGSizeMake(SCREEN_WIDTH - 30, MAXFLOAT) ].height;
NSMutableAttributedString* text =[[NSMutableAttributedString alloc]initWithString:string];
NSMutableParagraphStyle * paragraphStyle =[[NSMutableParagraphStyle alloc]init];
//设置行距
[paragraphStyle setLineSpacing:15.0f];
[text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
//设置一定Range区间文字颜色
[text addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 30)];
//设置一定Range区间文字下划线
[text addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, 30)];
label.attributedText = text;
[self.view addSubview:label];
[label sizeToFit];
网友评论