Programming multiline mixed uiview types text

1 Answers

Two ways I can think of:

  • use CoreText with NSAttributedStrings. Difficult to achieve, especially for the links (you'll have to register a listener somewhere, compute on which "link" you "clicked", ...), but provides the best performance.
  • use a UIWebView and write the HTML on-the-fly. Less performant, but much more flexible.

How would I elegantly achieve multiline text that includes a combination of links, plain text, and formatted words? Right now, all I can think of is breaking each word into a token and displaying/positioning it differently (UILabel, UIButton, etc), however, this is terribly inefficient. Here is an example of what I am trying to achieve from the comments feature in Instagram.

Notice, formatted link to user name, indented multiline text, and possibility of inline links to hashtags.

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.