I am using this code
CGRect frame = self.mytext.frame;
frame.size.height = self.mytext.contentSize.height;
self.mytext.frame = frame;
But i
Finally i did it.
If anyone is having the same problem just had this code before
[_moreDetailsTextView sizeToFit];
To address this exact problem I made an auto-layout based light-weight UITextView subclass which automatically grows and shrinks based on the size of user input and can be constrained by maximal and minimal height - all without a single line of code.
Made primarily for use in Interface builder and only works with Auto layout
https://github.com/MatejBalantic/MBAutoGrowingTextView
GrowingTextViewHandler is an NSObject subclass which resizes text view as user types text. Handling resize via NSObject subclass is more useful rather than subclassing UITextView, because it will work for any subclass of UITextView. Here is the sample usage.
@interface ViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
@property (strong, nonatomic) GrowingTextViewHandler *handler;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.handler = [[GrowingTextViewHandler alloc]initWithTextView:self.textView withHeightConstraint:self.heightConstraint];
[self.handler updateMinimumNumberOfLines:3 andMaximumNumberOfLine:8];
}
- (void)textViewDidChange:(UITextView *)textView {
[self.handler resizeTextViewWithAnimation:YES];
}
@end
Recently I have found this CSGrowingTextView that sizes while you type, maybe it can help: https://github.com/cloverstudio/CSGrowingTextView
Neither of answers worked for me. I have editable UITextView that I want to dynamically expand in height as the text grows in multiple lines.
It worked fine for iOS6 but I had problems on iOS7 with scrolling the text view in order to keep the cursor visible.
The solution for me was to put bottom inset for text view on iOS7. Like this:
_textView.contentInset = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") ? UIEdgeInsetsMake(0, 0, DEFAULT_FONT_SIZE, 0) : UIEdgeInsetsZero;
Satisfiable results. Good luck.
Noticed in IOS7 sizeToFit wasn't working also - perhaps the solution may help you too
[UITEXTVIEW sizeToFit];
[UITEXTVIEW layoutIfNeeded];