Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know of two fundamental approaches to creating a rich text editor in iOS 5:</p> <ol> <li><p>Use Core Text and a custom view. I don't have any experience with this approach.</p></li> <li><p>Use a UIWebView (instead of a UITextView) and the <code>contentEditable</code> HTML attribute. The basic idea is to load a custom HTML document from your app resources directory. The bare minimum that it needs is this:</p> <p>&lt;div contentEditable&gt;TEXT_PLACEHOLDER&lt;/div&gt;</p></li> </ol> <p>To initialize the rich text editor view: 1. Load the contents of this file into an <code>NSMutableString</code> and replace the TEXT_PLACEHOLDER string with the text you want to edit. 2. Send the <code>loadHTMLString:baseURL:</code> message to the UIWebView with that HTML string.</p> <p>Now you have a UIWebView displaying your text inside a <code>div</code> with <code>contentEditable</code>. At this point, you should be able to run your app tap on the text, and be presented with a cursor and be able to add/remove text. The next step is to add rich text formatting functionality. This is done with a set of simple javascript function calls. See <a href="https://developer.mozilla.org/en/rich-text_editing_in_mozilla" rel="nofollow noreferrer">the Mozilla documentation on contentEditable</a> for a great reference. You will also want to add a Javascript function to your HTML template file like this:</p> <pre><code>function getHtmlContent() { return document.getElementById('myDiv').innerHTML; } </code></pre> <p>So you can easily retrieve the edited text as HTML using <code>[myWebView stringByEvaluatingJavaScriptFromString:@"getHtmlContent()"]</code>. You can also add custom context menu items like you show in the screen shot in your question.</p> <p>If you have access to the Apple iOS dev center, the WWDC session <a href="https://developer.apple.com/videos/play/wwdc2011/511/" rel="nofollow noreferrer">Rich Text Editing in Safari on iOS</a> talks all about this approach.</p> <p>A variation of this approach is to use a third-party rich text editor like TinyMCE. I've heard of some success with integrating this into a UIWebView in iOS 5. Again this relies on the contentEditable attribute.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload