UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 0, 20)];
lab.font = [UIFont systemFontOfSize:14.0f];
[self.view addSubview:lab];
NSString *str = @"啦啦啦啦啦啦";
lab.text = str;
lab.backgroundColor = [UIColor redColor];
CGSize maxSize = CGSizeMake(MAXFLOAT, 20);
NSDictionary *params = @{
NSFontAttributeName : [UIFont systemFontOfSize:14.0f]
};
// CGSize textSize = [str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:params context:nil].size;
CGSize textSize = [self getSizeWithMaxSize:maxSize text:str params:params];
[lab setFrame:CGRectMake(lab.frame.origin.x, lab.frame.origin.y, textSize.width, lab.frame.size.height)];