int targetTextViewWidth=424;
NSString *msgStr=@"What are you doing?";
UIFont *tableCellMsgFont=[UIFont systemFontOfSize:16];
UITextView *textView = [[UITextView alloc] init];
[textView setFont:tableCellMsgFont];
textView.text=msgStr;
CGSize sizeThatFitsTextView = [textView sizeThatFits:CGSizeMake(targetTextViewWidth, MAXFLOAT)];
int lines = (int)lroundf(sizeThatFitsTextView.height) / (int)lroundf(tableCellMsgFont.lineHeight);
NSLog(@"lines=%d",(int)lines);
注意:當行數多過10, 可能不太精準.