//行間距
/*
* space 行間距設(shè)置
* label 原始label
* string 需要輸入的內(nèi)容
*/
+ (UILabel *)setLineSpace:(CGFloat)space FromLabel:(UILabel *)label withString:(NSString *)string;
{
label.numberOfLines = 0;
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
[paraStyle setLineSpacing:space];
[attributeString addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, [string length])];
label.attributedText = attributeString;
[label sizeToFit];
return label;
}
//自適應(yīng)高度和高度
/*
* string 需要輸入的內(nèi)容
* label? 原始label
* height 最大高度
* space? 行間距
*/
+ (UILabel *)setAutoFrame:(NSString *)string FromLabel:(UILabel *)label withMaxHeight:(CGFloat)height byLineSpace:(CGFloat)space;
{
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByTruncatingTail;
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
[paraStyle setLineSpacing:space];
[attributeString addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, [string length])];
label.attributedText = attributeString;
CGSize size = [label sizeThatFits:CGSizeMake(label.frame.size.width, height)];
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, size.width, size.height);
return label;
}