I was hoping to use the answer here to solve my problem, but the UITextView has no intrinsicContentSize method. Does anyone know how I can do this? On Android, all I have to do is say βwrap-contentβ in the layout file. But here on iOS, hell.
As for suggestions, resize the UITextField when typing (using Autolayout) , I'm not sure why these guys use IBAction in the delegate signature. In any case, they do not work for me.
UPDATE
I thought I solved the problem with the following. But "growth" is temporary. The field is only growing as I type. As soon as I stop typing, it returns to a smaller size. How can I make it more permanent?
- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { [self resizeTextViewToFitContent:textView]; } - (void)resizeTextViewToFitContent:(UITextView *)textView { CGRect frame = textView.frame; frame.size.height=[self heightOfTextView:textView]+5; textView.frame=frame; } -(CGFloat)heightOfTextView:(UITextView *)textView { CGRect reviewTextFrame = [textView.attributedText boundingRectWithSize:CGSizeMake(textView.bounds.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil]; return CGRectGetHeight(reviewTextFrame); }
ios iphone autolayout uitextview
Katedral Pillon Jan 24 '15 at 20:16 2015-01-24 20:16
source share