I had a similar need a while back, and made a category to support resizing of each UITextView
. Just add this category to your project, import it to the class that you need it in, and call autoAdjustHeight
on your UITextView
when you want to resize it.
UITextView+Resizeable.h:
@interface UITextView (Resizeable)
-(void)autoAdjustHeight;
@end
UITextView+Resizeable.m:
#import "UITextView+Resizeable.h"
@implementation UITextView (Resizeable)
-(void)autoAdjustHeight {
CGFloat fixedWidth = self.frame.size.width;
CGSize newSize = [self sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = self.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
self.frame = newFrame;
self.scrollEnabled = NO;
}
@end