IOS 6和ios7 不一样,所以,我们分开来:
IOS6:
//计算实际frame大小,并将label的frame变成实际大小
CGSize size01 = [ssizeWithFont:[UIFontsystemFontOfSize:15.0f]constrainedToSize:sizelineBreakMode:NSLineBreakByWordWrapping]; [label setFrame:CGRectMake(,, size01.width, size01.height)];
IOS7:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
NSString *str=@"发恶无法奶奶问服务就啃发觉我看能否尽快稳罚款金额为你放假";
label.text=str;
UIFont *font=[UIFont systemFontOfSize:];
label.font=font; //拆行
label.lineBreakMode=NSLineBreakByWordWrapping;
//设置多行
[label setNumberOfLines:]; //设置最大尺寸的宽和高
CGSize size=CGSizeMake(, );
//获取当前字体
NSDictionary *dict=@{NSFontAttributeName: [UIFont systemFontOfSize:]};
CGSize authSize=[str boundingRectWithSize:size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:dict
context:nil].size;
label.frame=CGRectMake(, , authSize.width, authSize.height);
[self.view addSubview:label];