1:计算字符串的长度:
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],};
CGSize textSize = [text boundingRectWithSize:CGSizeMake(KscreenWith, 35) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
2:计算字符串的高度:
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],};
CGSize textSize = [text boundingRectWithSize:CGSizeMake(KscreenWith-8, 35) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
CGFloat textHeight =MAX(textViewHeight, textSize.height+10);
self.textView .frame =CGRectMake(CGRectGetMaxX(self.titleLable.frame)+spacing, self.titleLable.frame.origin.y, textViewWid, textHeight);
注意:这里减去8是有道理的。