UILabel 自动适应文字

//显示多行文字
CGSize size = CGSizeMake(Width_mainScreen - 59, MAXFLOAT);
UIFont *fonts = [UIFont systemFontOfSize:15.0];
NSStringDrawingOptions options =  NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
NSDictionary * arrtibutes = @{NSFontAttributeName:fonts};
CGRect rect = [label.text boundingRectWithSize:size options:options attributes:arrtibutes context:nil];
CGSize msgSie =  rect.size;
[label setFont:[UIFont boldSystemFontOfSize:15]];
label.frame = CGRectMake(43,70, Width_mainScreen - 59,msgSie.height);
label.lineBreakMode = NSLineBreakByCharWrapping;//实现文字多行显示
label.numberOfLines = 0;
posted @ 2015-12-28 08:33  zs十二  阅读(133)  评论(0)    收藏  举报