1

I am new in iOS programming.

In my application (ios + Objective-C + Auto resize) I have UITextView inside of UIView. Initially height of UIView is 50 and UITextView is 30 at the bottom of screen.

What I want to do is, I want to change height of both components as user type some text, i.e y and height of both components will change.

I use below code but its not working properly.

- (void)textViewDidChange:(UITextView *)textView
{
  CGFloat fixedWidth = textView.frame.size.width;
  CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
  CGRect newFrame = textView.frame;

  CGRect viewFrame = _viewMsg.frame;
  viewFrame.origin.y = viewFrame.origin.y - (newSize.height - 30.0);
  viewFrame.size.height = viewFrame.size.height + (newSize.height - 30.0);
  _viewMsg.frame = viewFrame;

  newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
  textView.frame = newFrame;

}

Please explain me how dynamically resizing work with Auto Resize.

User_1191
  • 981
  • 2
  • 8
  • 24

1 Answers1

0

You can change as per below code

- (void)textViewDidChange:(UITextView *)textView
{
    CGFloat fixedWidth = textView.frame.size.width;
    CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
    CGRect newFrame = textView.frame;
    newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
    textView.frame = newFrame;


    CGRect viewFrame = _viewMsg.frame;
    viewFrame.size.height = _viewMsg.frame.size.height;
    viewFrame.origin.y= self.view-viewFrame.size.height-30;
    _viewMsg.frame =viewFrame;

}

it me help to increase your View & textView height.

CodeChanger
  • 7,953
  • 5
  • 49
  • 80