核心代码如下,用的时候直接把代码复制过去就可以了,参数传入你需要计算的label的文字
```-(void)calculateLine:(NSString*)title
{
CGSizesize = [titlesizeWithAttributes:@{NSFontAttributeName: [UIFontsystemFontOfSize:14.0]}];
//首先计算一行的高度
CGSizetotleSize = [titleboundingRectWithSize:CGSizeMake(YYTScreenW-28,MAXFLOAT)options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName: [UIFontsystemFontOfSize:14.0]}context:nil].size;
intnumberLine =ceil(totleSize.height/ size.height);
self.BtntopCons.constant= -28;
if(numberLine >2) {
self.BtntopCons.constant=4;
self.openBtn.hidden=NO;
[self.viewlayoutSubviews];
}
}
```