iOS中label根据字体和行间距返回高度

NSMutableAttributedString *attibutesString = [[NSMutableAttributedStringalloc]initWithString:model.content]; //model.content是文本

NSMutableParagraphStyle *paraghStyle =[[NSMutableParagraphStylealloc] init];

[paraghStyle setLineSpacing:8];

[attibutesString addAttribute:NSParagraphStyleAttributeNamevalue:paraghStyle range:NSMakeRange(0, model.content.length)];

_labelText.attributedText = attibutesString;


//在这传进去字体和行距

NSDictionary *attribute =@{NSFontAttributeName:_labelText.font,NSParagraphStyleAttributeName:paraghStyle};

CGSize size = [model.contentboundingRectWithSize:CGSizeMake(SCR_W -20, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:attributecontext:nil].size;

//返回高度

_labelText.frame =CGRectMake(10,60, size.width, size.height);




你可能感兴趣的:(ios,UILabel,字体,自适应)