/**
@method 獲取指定寬度width的字符串在UITextView上的高度
@param textView 待計算的UITextView
@param Width 限制字符串顯示區(qū)域的寬度
@result float 返回的高度
*/
- (float) heightForString:(UITextView *)textView andWidth:(float)width{
CGSize sizeToFit = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
return sizeToFit.height;
}
使用方法
UITextView * txtView = [[UITextView alloc] init];
txtView.text = noticeStr;
float strHeight = [self heightForString:txtView andWidth:ScalingWidth(280.0)];
注:以前使用的方法總有不準(zhǔn)確的情況佑稠,這個一試一個準(zhǔn),??