0

我使用图像选择器在文本视图中插入了库中的图像,

在 pickeDelegatedidFinishPickingImage方法中

imgview = [[UIImageView alloc] initWithImage:image];

            NSString *messageText = [[NSString alloc]init];
            messageText = messageView.text;
            CGSize s = [messageText sizeWithFont:[UIFont systemFontOfSize:15] //define your textview font size
                               constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  //                                      lineBreakMode:UILineBreakModeWordWrap];   
            CGRect frame = CGRectMake(0.0f, s.height+10, 50, 50);//use YourImageView. height and width 
            imgview.frame=frame;

            //[imgview setFrame:CGRectMake(0, 0, 30,30) ];
            [messageView addSubview:imgview];

并使用以下委托方法逻辑实现了在最后一个文本末尾添加图像的逻辑

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
      if ( [text isEqualToString:@"\n"] ) {

      }
      else
      {
            NSString *yourstring = [[NSString alloc]init];
            yourstring = textView.text;
            CGSize s = [yourstring sizeWithFont:[UIFont systemFontOfSize:15] //define your textview font size
                              constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  // - 40 For cell padding
                                  lineBreakMode:UILineBreakModeWordWrap];   
            CGRect frame = CGRectMake(0.0f, s.height+10, 50, 50);//use YourImageView. height and width 
            imgview.frame=frame;
      }
      return YES;
}

但是每次光标在图像视图之前开始时,

i need to jump/ move the cursor after the image when ever i added the image, jus like as folows,

我的要求是用户可以在文本视图中输入文本,他可以在文本视图中添加图像,然后从图像后的下一行,他可以再次输入文本,

就像我们在这个堆栈中附加图像一样通过流框这样

在此处输入图像描述

插入图片后,他可以再次输入文字,

如何做到这一点任何帮助..提前谢谢

我之前的问题:向 UITextView 添加图像

4

1 回答 1

0

如果您想在插入图像后对文本字段做出响应,那么-

    [YOURTEXTFIELD becomeFirstResponder];
于 2012-11-07T10:09:28.590 回答