我有一個簡單的textView誰的數據動態填充。一旦數據填充後,我想調整textview的高度,這樣我就不會看到垂直滾動,也不會看到文本被剪切。Autoexpand UITextView高度包含動態加載的完整文本
難道只需選擇其中一種textView模式即可完成,還是需要執行programaticaaly?
我有一個簡單的textView誰的數據動態填充。一旦數據填充後,我想調整textview的高度,這樣我就不會看到垂直滾動,也不會看到文本被剪切。Autoexpand UITextView高度包含動態加載的完整文本
難道只需選擇其中一種textView模式即可完成,還是需要執行programaticaaly?
您可以通過添加的這幾行代碼到你的應用程序做到這一點: -
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
}
您必須以編程方式執行此操作。使用NSString UIKit Additions來計算你的UITextView的高度:
sizeWithFont:
sizeWithFont:constrainedToSize:
sizeWithFont:constrainedToSize:lineBreakMode:
sizeWithFont:forWidth:lineBreakMode:
sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: