- (NSAttributedString *)attributedTextArray:(NSArray *)texts
textColors:(NSArray *)colors
textfonts:(NSArray *)fonts
lineSpacing:(CGFloat)l_spacing{
if(texts.count == 0){
return nil;
}
NSMutableAttributedString *resultAttributedStr = [[NSMutableAttributedString alloc] init];
for(int i=0; i<texts.count; i++)
{
NSString *text = texts[i];
NSMutableAttributedString *mAttributedStr = [[NSMutableAttributedString alloc] initWithString:text];
[mAttributedStr addAttribute:NSForegroundColorAttributeName value:colors[i] range:NSMakeRange(0, text.length)];
[mAttributedStr addAttribute:NSFontAttributeName value:fonts[i] range:NSMakeRange(0, text.length)];
[resultAttributedStr appendAttributedString:mAttributedStr];
}
if(l_spacing>0){
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = l_spacing;
[resultAttributedStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, resultAttributedStr.length)];
}
return resultAttributedStr;
}
- (CGSize)sizeLabelWidth:(CGFloat)width
attributedText:(NSAttributedString *)attributted{
if(width<=0){
return CGSizeZero;
}
UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, MAXFLOAT)];
lab.attributedText = attributted;
lab.numberOfLines = 0;
CGSize labSize = [lab sizeThatFits:lab.bounds.size];
return labSize;
}