- (void)viewDidLoad {
[super viewDidLoad];
// 转载请注明出处:http://blog.csdn.net/sevenquan
UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
textview.delegate = self;
textview.layer.borderColor = [UIColor blackColor].CGColor;
textview.layer.borderWidth = 1;
;
[self.view addSubview:textview];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
textView.frame = CGRectMake(100, 100, 100, [self heightForTextView:textView WithText:textView.text]);
return YES;
}
- (float) heightForTextView: (UITextView *)textView WithText: (NSString *) strText{
float fPadding = 10.0;
CGSize constraint = CGSizeMake(textView.contentSize.width - fPadding, CGFLOAT_MAX);
CGSize size = [strText sizeWithFont: textView.font constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
float fHeight = size.height + 25.0;
NSLog(@"---- :%f",fHeight);
return fHeight;
}