问题描述
我想在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 UITextView
s and UIImageView
s 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:
- 他们没有使用
UITextView
,而是一些自定义视图。这种事情很难复制。 - 他们在
UITextView上覆盖
作为子视图并设置UIImageView
UITextView
的contentInset,因此没有重叠。 - 他们使用单独的
UIView
来包含UITextView
和UIImageView
作为子视图,只需根据需要安排这些子视图。
- They're not using a
UITextView
, but instead some custom view. That sort of thing is difficult to replicate. - They are overlaying a
UIImageView
over theUITextView
as a subview and setting the contentInset of theUITextView
so there is no overlap. - They are using a separate
UIView
to contain both theUITextView
andUIImageView
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中插入多媒体内容的方式相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!