Alex Rivera | Logout

UITextView with Syntax Highlighting

Asked 2010-09-04T13:49:43.717
43

How to do Syntax Highlighting in a UITextView, specifically syntax highlighting (and detection) for Objective-C on the iPhone?

Some of my ideas of how to do this:

  • NSAttributedString. Now available in iOS 3.2 and greater. But how would I put a NSAttributedString into a UITextView?
  • UIWebView. Overlay it when the user finished editing and color the text with CSS stylesheets. But how would I do this in a UIWebView, giving it the text and then coloring it?
Edit
Report

1 Answer

12

Since iOS 5 you can use a UIWebView and set contenteditable="true" on a div in it. This makes the UIWebView open a keyboard up and allow the user to directly input text into the DOM. You can then write a webapp that does syntax highlighting. You can communicate with the cocoa app with custom URLs.

The only issue I have is you don't seem to get spellchecking.

answered 2011-10-27T23:45:16.347

Your Answer