用于渲染 HTML 内容的 Core Text
我想知道是否有办法使用核心文本渲染 html 内容, 因为普通的 UIWebView 加载速度非常慢。
我有非常基本的需求:
- 读取p标签
- 读取span标签
- 使用颜色
- 使用字体和尺寸
仅此而已。
非常感谢你!
k
I was wondering if is there a way to render html content using core text,
because the common UIWebView is slow as hell to load up.
I've got very basic needs:
- reading p tags
- reading span tags
- using colors
- using fonts and sizes
that's all.
thanks you so much!
k
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我用一种有点棘手的方式解决了这个问题。
我实现了一个 HTMLParser 来提取需要格式化的字符
以不同的方式。然后我继续在 Core-Text 中使用该字符串。
我的参考文献是
[HTMLParser] https://github.com/zootreeves/Objective-C-HMTL -解析器
请记住,这个问题是通过逐个解析两个标签来实现的
(例如
...
)
[CoreText 的启动]
https://github.com/jonasschnelli/I7CoreTextExample
ok I solved this in a bit tricky way.
I implemented a HTMLParser to extract the characters that I needed to be formatted
in a different way. than I proceeded to use the string in Core-Text.
my references were
[HTMLParser] https://github.com/zootreeves/Objective-C-HMTL-Parser
remember that this one has a problem by parsing two tags one after another
(e.g. < p >< span >. . . < /span >< /p >)
[kickstart for CoreText]
https://github.com/jonasschnelli/I7CoreTextExample
请参阅这个开源项目: https://github.com/Cocoanetics/DTCoreText
这不会有帮助您可以使用 Core Text 渲染属性字符串,但它会帮助您将 HTML 转换为
NSAttributedString
。See this open-source project: https://github.com/Cocoanetics/DTCoreText
It won't help you render an attributed string with Core Text, but it will help you convert HTML to an
NSAttributedString
.这个问题已经在这里得到了更好的回答:
https://stackoverflow.com/a/18886718/187258
无需使用DTCoreText 如果您的目标是 iOS 7 及更高版本(您现在应该这样做)。
这是答案中代码的重印(重要标志:
NSHTMLTextDocumentType
):This question has already been answered better here:
https://stackoverflow.com/a/18886718/187258
No need to use DTCoreText if you're targeting iOS 7 and up (which you should be doing, by now).
Here's a reprint of the code in the answer (important flag:
NSHTMLTextDocumentType
):