//iOS7放弃使用“ CGSize actualsize = [tstring sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping]; ”
//基本设置
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
NSString *text = @"测试:阿啊阿啊阿啊阿啊阿啊阿啊阿啊阿啊阿啊阿啊阿啊阿啊阿啊阿asdafdddddaaaaaaaaajhkjkgghghghghghghghghghgghghhghghghghghghg啊阿啊阿啊阿啊阿啊阿啊";
label.text = text;
UIFont *textFont = [UIFont systemFontOfSize:14.f];
label.font = textFont;
//折行
label.lineBreakMode = NSLineBreakByWordWrapping;
//必须写,否则只显示一行
[label setNumberOfLines:0];
[self.view addSubview:label];
//最大尺寸
// MAXFLOAT 为可设置的最大高度
CGSize size = CGSizeMake(300, MAXFLOAT);
//获取当前那本属性
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:textFont,NSFontAttributeName, nil];
//实际尺寸
CGSize actualSize = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
label.frame = CGRectMake(10, 70, actualSize.width,actualSize.height);