本文介绍了如何在UITextView中插入UIImageView的方式与iphone默认消息(SMS)应用程序用于在UITextView中插入多媒体内容的方式相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在UITextView的工具栏中插入UIImageView,其发送和相机按钮的方式与iPhone默认短信应用程序相同。

I want to insert UIImageView in UITextView of Toolbar having send and camera button in the same way as iPhone default SMS app do.

推荐答案

最好使用 UIScrollView 并管理 UITextView UIImageView s。 UITextView 不支持使用文本内联添加图片。事实上,除了多行文字之外,它并不支持任何其他内容。

You would be better off using a UIScrollView and managing UITextViews and UIImageViews in it. UITextView doesn't support adding image inline with text. In fact, it doesn't really support anything other than multiline text.

根据下面的评论,我可以想到三件事情来获取图像作为文本输入框:

Per your comment below, there are three things I can think of to get the image as part of the text entry box:


  1. 他们没有使用 UITextView ,而是一些自定义视图。这种事情很难复制。

  2. 他们在 UITextView上覆盖 UIImageView 作为子视图并设置 UITextView 的contentInset,因此没有重叠。

  3. 他们使用单独的 UIView 来包含 UITextView UIImageView 作为子视图,只需根据需要安排这些子视图。

  1. They're not using a UITextView, but instead some custom view. That sort of thing is difficult to replicate.
  2. They are overlaying a UIImageView over the UITextView as a subview and setting the contentInset of the UITextView so there is no overlap.
  3. They are using a separate UIView to contain both the UITextView and UIImageView as subviews and simply arrange those subviews as needed.

2& 3非常相似(只是略有不同的方法),可能是你最好的方法。就个人而言,我认为3可能是最好的,因为它可以让你最大程度地控制两个视图的位置,但是2也应该可以正常工作。

Both 2 & 3 are very similar (just slightly different approaches) and probably your best approach. Personally, I think 3 is probably the best, since it give you the most control over the position of both views, but 2 should also work fine.

这篇关于如何在UITextView中插入UIImageView的方式与iphone默认消息(SMS)应用程序用于在UITextView中插入多媒体内容的方式相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:58