2012-05-15 25 views

回答

7

您可以通過添加的這幾行代碼到你的應用程序做到這一點: -

CGRect frame = textView.frame; 
frame.size.height = textView.contentSize.height; 
textView.frame = frame; 

實施的TextView的日委託方法驗證碼

- (void)textViewDidChange:(UITextView *)textView 
{ 
// you might have to compare the frames if it needs changing as user might not have added an extra line 
} 
1

您必須以編程方式執行此操作。使用NSString UIKit Additions來計算你的UITextView的高度:

sizeWithFont: 
sizeWithFont:constrainedToSize: 
sizeWithFont:constrainedToSize:lineBreakMode: 
sizeWithFont:forWidth:lineBreakMode: 
sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: