简体   繁体   English

如何像iPhone上的MMS应用一样在一个视图中插入和删除图像和文本

[英]How to insert and delete image and text in one view just like MMS apps on iPhone

I would like to implement something like MMS app on iPhone, where user will have an option to include an image and text. 我想在iPhone上实现类似MMS应用的功能,用户可以选择包含图像和文本。

The way I did is i created a UIUiew and included a UITextView and UIImageView inside it, and when user selects an image it goes in to the UIImageView and the user can type in the UITextView. 我做的方法是创建一个UIUiew,并在其中包含UITextView和UIImageView,当用户选择图像时,它进入UIImageView,并且用户可以键入UITextView。

But the problem that I am facing is once you insert a UIImage how do you put a cursor after the image so that user can delete(backspace) the image and that space free's up and it becomes available for the user to type in more text. 但是我面临的问题是,一旦插入UIImage,如何在图像后放置光标,以便用户可以删除(退格)图像,并且可以释放空间,并且用户可以键入更多文本。

Simple answer: You cannot mix text and images in a UITextView . 简单的答案:您不能在UITextView混合文本和图像。 If you want to achieve a behavior like this, you should look into using Core Text to render the text yourself (it supports other elements inside the text via certain callbacks through which you tell the text system how much space it is supposed to reserve for the image. 如果要实现这样的行为,则应考虑使用Core Text自己呈现文本(它通过某些回调支持文本中的其他元素,通过这些回调,您可以告诉文本系统应为该文本空间保留多少空间。图片。

To make the text editable, you would have to implement the text editing protocols UITextInput and UIKeyInput . 要使文本可编辑,您必须实现文本编辑协议UITextInputUIKeyInput Which means you have to basically write your own text editor. 这意味着您必须基本上编写自己的文本编辑器。 It's possible but it's a lot of work. 可能,但是需要很多工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM