var str = "文字测试1234567890poiuytrewqadfghkl;'.,mnbvxzzhelllo wen li hua ni hao sjfsjflsfjlsa;j a;fja;lj;jkkkk'lll"
var _label_left = UILabel();
_label_left.frame = CGRectMake(10, 300, 1000, 15);//当适应一行时设置
_label_left.font = UIFont.systemFontOfSize(20);
_label_left.text = str;
var size = fitContentSize(_label_left, textString: str);
_label_left.frame = CGRectMake(10, 300, size.width, size.height);
_label_left.numberOfLines = 0;//当需要适应多行时设置
//先设置label.font,和label最大frame
class func size_of_label(label:UILabel, textString:NSString) -> CGSize
{
label.lineBreakMode = NSLineBreakMode.ByWordWrapping;
var para = NSMutableParagraphStyle();
para.lineBreakMode = NSLineBreakMode.ByWordWrapping;
var attr = [NSFontAttributeName:label.font,NSParagraphStyleAttributeName:para.copy()];
var size = textString.boundingRectWithSize(CGSizeMake(label.frame.width, label.frame.height), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attr, context: nil).size;
return size;
}