在detail視圖中創建標簽。設置相應文本時需要設置標簽的高度。
NSString *mytitleString = [discussionData valueForKey:@"Name"];
CGSize size = [mytitleString sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(500, CGFLOAT_MAX)];
float lbltitleheight = size.height;
lbltitle.text = mytitleString;
如果文本很多行就無法設置標簽的高度了,怎麼辦?
先給UILabel賦文本,再重新計算,重置uilabel的frame
NSString *mytitleString = [discussionData valueForKey:@"Name"];
lbltitle.text = mytitleString;
lbltitle.font=[UIFont systemFontOfSize:14.0];
CGSize size = [lbltitle.text sizeWithFont:lbltitle.font constrainedToSize:CGSizeMake(500, CGFLOAT_MAX)];
/////重置高度
lbltitle.frame=CGRectMake(lbltitle.frame.origin.x,lbltitle.frame.origin.y,size.width,size.height);