<small id='SYlKS'></small><noframes id='SYlKS'>

      1. <legend id='SYlKS'><style id='SYlKS'><dir id='SYlKS'><q id='SYlKS'></q></dir></style></legend>

        <i id='SYlKS'><tr id='SYlKS'><dt id='SYlKS'><q id='SYlKS'><span id='SYlKS'><b id='SYlKS'><form id='SYlKS'><ins id='SYlKS'></ins><ul id='SYlKS'></ul><sub id='SYlKS'></sub></form><legend id='SYlKS'></legend><bdo id='SYlKS'><pre id='SYlKS'><center id='SYlKS'></center></pre></bdo></b><th id='SYlKS'></th></span></q></dt></tr></i><div id='SYlKS'><tfoot id='SYlKS'></tfoot><dl id='SYlKS'><fieldset id='SYlKS'></fieldset></dl></div>
      2. <tfoot id='SYlKS'></tfoot>
        • <bdo id='SYlKS'></bdo><ul id='SYlKS'></ul>

        像在 iMessage 中一样在 Uitextview 中添加 UIImageview

        Add UIImageview in Uitextview as in iMessage(像在 iMessage 中一样在 Uitextview 中添加 UIImageview)
      3. <small id='Iq9pG'></small><noframes id='Iq9pG'>

          <tbody id='Iq9pG'></tbody>
          <i id='Iq9pG'><tr id='Iq9pG'><dt id='Iq9pG'><q id='Iq9pG'><span id='Iq9pG'><b id='Iq9pG'><form id='Iq9pG'><ins id='Iq9pG'></ins><ul id='Iq9pG'></ul><sub id='Iq9pG'></sub></form><legend id='Iq9pG'></legend><bdo id='Iq9pG'><pre id='Iq9pG'><center id='Iq9pG'></center></pre></bdo></b><th id='Iq9pG'></th></span></q></dt></tr></i><div id='Iq9pG'><tfoot id='Iq9pG'></tfoot><dl id='Iq9pG'><fieldset id='Iq9pG'></fieldset></dl></div>

              1. <legend id='Iq9pG'><style id='Iq9pG'><dir id='Iq9pG'><q id='Iq9pG'></q></dir></style></legend>
                  <bdo id='Iq9pG'></bdo><ul id='Iq9pG'></ul>

                  <tfoot id='Iq9pG'></tfoot>

                • 本文介绍了像在 iMessage 中一样在 Uitextview 中添加 UIImageview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 UItextview 并为工具栏按钮添加一个额外的 inputAccessoryview 以执行其他操作.我的工具栏有一个相机图标,它从 UIImagePickerController 获取图像,我必须将此图像添加到我的 UItextview 中.

                  I am using UItextview and adding an extra inputAccessoryview for toolbar buttons to perform additional actions. My toolbar has a camera icon which gets the image from UIImagePickerController and Ι have to add this image in my UItextview.

                  现在我可以做到这一点:

                  Right now Ι am able to do this with :

                  [myTextView addSubView:imageView];
                  

                  但是那样,总是在文本视图的开头添加图像,我想要的是将它添加到当前光标位置.我也想删除这张图片,就像我从 textview 中删除文本一样.

                  But that way, always adds the image at the beginning of the textview and what Ι want is to add it at the current cursor location. I would also like to remove this image just like I remove the text from textview.

                  为了记录,我还尝试获取 UItextview 文本的选定范围并尝试在该位置插入我的 imageview 但它不起作用.

                  Just for the record, Ι also tried getting UItextview text's selected range and tried inserting my imageview at that location but it did not work.

                  编辑代码:

                  NSMutableAttributedString * mas = [[NSMutableAttributedString alloc]initWithString:self.commentsTextView.text];
                  NSRange cursorPoistion = [self.commentsTextView selectedRange];
                  
                  UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
                  
                  NSTextAttachment* onionatt = [NSTextAttachment new];
                  onionatt.image = chosenImage;
                  onionatt.bounds = CGRectMake(0,-5,200,200);
                  NSAttributedString* onionattchar = [NSAttributedString attributedStringWithAttachment:onionatt];
                  
                  [mas insertAttributedString:onionattchar atIndex:(cursorPoistion.location + cursorPoistion.length)];
                  
                  self.commentsTextView.attributedText = mas;
                  

                  推荐答案

                  这在 iOS 7 之前是不可能的.现在,在 iOS 7 中,您可以做到这一点,因为 UITextView 是基于 Text Kit 的,并且内联图像可以在 NSAttributedString 中.

                  This was impossible before iOS 7. Now, in iOS 7, you can do it because UITextView is based on Text Kit and inline images are possible in an NSAttributedString.

                  这是一个非常简单的示例,我在文本中的洋葱"一词之后添加了一张洋葱图片(mas 是我的 NSMutableAttributedString):

                  Here's a very simple example where I add a picture of onions just after the word "Onions" in my text (mas is my NSMutableAttributedString):

                  UIImage* onions = [self thumbnailOfImageWithName:@"onion" extension:@"jpg"];
                  
                  NSTextAttachment* onionatt = [NSTextAttachment new];
                  onionatt.image = onions;
                  onionatt.bounds = CGRectMake(0,-5,onions.size.width,onions.size.height);
                  NSAttributedString* onionattchar = [NSAttributedString attributedStringWithAttachment:onionatt];
                  
                  NSRange r = [[mas string] rangeOfString:@"Onions"];
                  [mas insertAttributedString:onionattchar atIndex:(r.location + r.length)];
                  
                  self.tv.attributedText = mas;
                  

                  这是一个小的内嵌图像.听上去好像是想把自己的图片加到自己的段落里,但是原理是完全一样的.

                  That's for a small inline image. It sounds like you want to add your image in a paragraph of its own, but the principle is exactly the same.

                  这篇关于像在 iMessage 中一样在 Uitextview 中添加 UIImageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Difference between retain and copy?(保留和复制的区别?)
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  What is the difference between quot;copyquot; and quot;retainquot;?(“复制和“复制有什么区别?和“保留?)
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  • <i id='znjmM'><tr id='znjmM'><dt id='znjmM'><q id='znjmM'><span id='znjmM'><b id='znjmM'><form id='znjmM'><ins id='znjmM'></ins><ul id='znjmM'></ul><sub id='znjmM'></sub></form><legend id='znjmM'></legend><bdo id='znjmM'><pre id='znjmM'><center id='znjmM'></center></pre></bdo></b><th id='znjmM'></th></span></q></dt></tr></i><div id='znjmM'><tfoot id='znjmM'></tfoot><dl id='znjmM'><fieldset id='znjmM'></fieldset></dl></div>

                    <small id='znjmM'></small><noframes id='znjmM'>

                        <legend id='znjmM'><style id='znjmM'><dir id='znjmM'><q id='znjmM'></q></dir></style></legend>

                          <tbody id='znjmM'></tbody>
                        1. <tfoot id='znjmM'></tfoot>
                            <bdo id='znjmM'></bdo><ul id='znjmM'></ul>