UITextView *textView = [[UITextViewalloc] init];
UIFont *font = [UIFontsystemFontOfSize:16];
textView.backgroundColor = [UIColorwhiteColor];
textView.textColor = [UIColorblackColor];
NSString *str =@"TextView 自适应高度";
textView.text = str;
CGSize size = CGSizeMake(320,1000);
CGRect textRect=[[NSStringstringWithFormat:@"%@\n ",textView.text]boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin
attributes:[NSDictionarydictionaryWithObjectsAndKeys:font,NSFontAttributeName,nil] context:nil];
textView.frame =CGRectMake(100,100, 200, textRect.size.height);
[self.viewaddSubview:textView];