如何在iOS中显示和编辑HTML [英] How display and edit HTML in iOS
问题描述
使用UIWebView,我可以很好地显示HTML。使用UITextView,我可以编辑HTML。我可以用什么显示和编辑HTML?
With UIWebView, I can display HTML very well. With UITextView, I can edit HTML. With what can I both display and edit HTML?
有没有可用的开源项目或教程?
Is there any open source project or tutorial available?
推荐答案
您可以在 UIWebView
中使用内置的WYSIWYG编辑器来显示html。那里有很多所见即所得的编辑器。我喜欢 CKEditor ( demo )。
You can show your html inside a UIWebView
with a WYSIWYG editor inside. There are a lot of WYSIWYG editors out there. I like CKEditor (demo).
请参见开发人员文档-集成,用于设置/获取WYSIWYG编辑器的文本。
See the Developer Documentation - Integration for how to set / get the text of the WYSIWYG editor.
- 下载脚本文件并将其捆绑到您的应用中
- 包括脚本(来自ckeditor网站)
<head>
...
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
</head>
- 添加带有首字母的文本区域文本
<textarea id="editor1" name="editor1">
<p>Initial value.</p>
</textarea>
- 使用JavaScript创建编辑器
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>
如何从所见即所得编辑器中获取文本
使用脚本:
How to get Text from WYSIWYG Editor
Use the script:
var editor_data = CKEDITOR.instances.editor1.getData();
您可以使用 UIWebView
的 stringByEvaluatingJavaScriptFromString:
方法来运行JavaScript代码以根据需要获取/设置html内容。
You can use UIWebView
's stringByEvaluatingJavaScriptFromString:
method to run javascript code to get / set the html content as needed.
这篇关于如何在iOS中显示和编辑HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!