//给字符串添加行间距
- (NSAttributedString *)setLabelParagraphStyle:(NSString *)str lineSpaceSize:(CGFloat)spaceSize{
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:str];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = spaceSize; // 设置行间距
paragraphStyle.alignment = NSTextAlignmentJustified; //设置两端对齐显示
[attributedStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedStr.length)];
[attributedStr addAttribute:NSForegroundColorAttributeName value:[MMColor c999999Color] range:NSMakeRange(0, attributedStr.length)];
return attributedStr;
}
//计算添加了行间距之后Label的高度
- (CGFloat)widthForString:(NSString *)value fontSize:(CGFloat)fontSize{
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 8.0; // 设置行间距
paragraphStyle.alignment = NSTextAlignmentJustified; //设置两端对齐显示
NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:fontSize], NSParagraphStyleAttributeName:paragraphStyle };
//默认的
CGRect infoRect = [value boundingRectWithSize:CGSizeMake(MMscreenWidth-50, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dic context:nil];
return ceil(infoRect.size.height)+10;
}