NSAttributedString from HTML in the background thread

十年热恋 提交于 2019-11-29 11:08:34
user3762956

Yes you can't it in a background thread only on main thread. Use Oliver Drobnik's NSAttributedString+HTML class.

Code would be something like this -

NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithHTML:<html> dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:nil];

Link - https://github.com/InfiniteLoopDK/NSAttributedString-Additions-for-HTML/blob/master/Classes/NSAttributedString%2BHTML.m

You can try NSAttributedString+DDHTML. AFAIK it doesn't depend on WebKit and I used it successfully for simple HTMLs. I haven't tried using it in the background thread, but I suppose it shouldn't be a problem.

And watch out - it may crash when HTML includes font which is unavailable on iOS. I've issued a pull request for that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!