美文网首页
textViewHeight

textViewHeight

作者: seventhboy | 来源:发表于2018-08-17 11:06 被阅读11次
    • (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
      {
      CGRect frame = textView.frame;
      float height;
      if ([text isEqual:@""]) {

        if (![textView.text isEqualToString:@""]) {
      
            height = [ self heightForTextView:textView WithText:[textView.text substringToIndex:[textView.text length] - 1]];
      
        }else{
      
            height = [ self heightForTextView:textView WithText:textView.text];
        }
      

      }else{

            height = [self heightForTextView:textView WithText:[NSString stringWithFormat:@"%@%@",textView.text,text]];
      

      }

      frame.size.height = height;
      [UIView animateWithDuration:0.5 animations:^{

            textView.frame = frame;
      
        } completion:nil];
      

      return YES;
      }

    相关文章

      网友评论

          本文标题:textViewHeight

          本文链接:https://www.haomeiwen.com/subject/nxezbftx.html