有时候UILabel里面的内容是不固定的,因此需要根据内容和字体来计算UILabel的大小
可以用sizeWithFont方法来计算:
CGSize constraintSize= CGSizeMake(label.frame.size.width,MAXFLOAT);
CGSize expectedSize = [label.text sizeWithFont:label.font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, expectedSize.width, expectedSize.height);
CGSize expectedSize = [label.text sizeWithFont:label.font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, expectedSize.width, expectedSize.height);