UILabel自适应高度

NSString*  textstr =message;

NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:13]};

CGSize size =[textstr boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20,MAXFLOAT)options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;


UILabel* textlab =[[UILabel alloc]initWithFrame:CGRectMake(80,160,SCREEN_WIDTH-160,size.height)];

 textlab.textColor =[UIColor blackColor];

textlab.text = textstr;

textlab.font =[UIFont systemFontOfSize:13];

textlab.numberOfLines = 0;

[self.view addSubview:textlab];

你可能感兴趣的:(UILabel自适应高度)