3

我需要渲染一个(任意大)NSAttributedString,在这种情况下,来自(任意长)telnet 会话的 ANSI 彩色文本。文本不需要是可编辑的内联。我探索了几个选项:

  • UITextView seems to have by far the best performance and, since I'm targeting iOS 6, it's very easy to use with attributed strings. However, the textview gets progressively slower to render as more text is added, as it hits an HTML DOM parser each time I call setAttributedString: and blocks the UI.
  • I've tried a few core text rendering frameworks, TTTAttributedLabel and OHAttributedLabel, that also get progressively slower with more text. To be fair, they're labels probably not intended for this sort of thing!
  • UIWebView (gag) has some issues with rotation and keeping the text properly sized and framed, but I think I could work around it. I can convert my attributed string to HTML and use JavaScript to append (inject) new text as it is received. Surprisingly good performance here.
  • 一位朋友建议我将用户当前的滚动位置视为更大文档的视口,并且(可能带有核心文本)仅呈现我的属性字符串的可见部分。我担心这会如何影响滚动性能。

所以我转向你,勇敢的互联网。独立开发者的想法?网络视图是我最好的选择吗?

4

1 回答 1

0

您可以使用 UITableView 并将其拆分NSAttributedString为一个子字符串数组,每个子字符串都适合单元格的标签宽度。表格视图的数据源将索引到子字符串数组中,以确定原始字符串的哪一行应放置在每个单元格中。

于 2012-11-14T21:31:00.270 回答