我正在使用 DTCoreText 显示 HTML 代码。到目前为止一切正常,但现在我在此 HTML 代码中收到嵌入的推文,但它们无法正常工作。
正如 Twitter 文档中所说,推文嵌入了 blockquotes 标签,这是我收到的一个示例:
<blockquote class="twitter-tweet" lang="fr">
<p>
Here is the official <a href="https://twitter.com/hashtag/SPECTRE?src=hash">#SPECTRE</a> teaser poster <a href="http://t.co/3cn3iM6tf1">pic.twitter.com/3cn3iM6tf1</a></div>— James Bond (@007) <a href="https://twitter.com/007/status/577877246809141248">17 Mars 2015</a>
</blockquote>
仅显示文本。
我以这种方式在 DTCoreText 中注册了一个新类:
[DTTextAttachment registerClass:[MyBlockquoteClass class] forTagName:@"blockquote"];
MyBlockQuoteClass 有这个构造函数:
- (id)initWithElement:(DTHTMLElement *)element options:(NSDictionary *)options
{
self = [super initWithElement:element options:options];
if (self)
{
NSLog(@"THIS IS MY ELEMENT %@", element);
NSLog(@"THESE ARE MY OPTIONS %@", options);
}
return self;
}
当读取blockquote标签时调用构造函数,但options只有4个与字体颜色和大小相关的键,元素有很多属性但对我没有用,几乎所有东西都是nil,没有 child ,只有class = twitter-tweet"和 lang="fr",但是没有办法获取内容,所以我不能像我想做的那样在 UIWebView 中嵌入 block 引用。
我究竟做错了什么?也许使用 DTCoreText 有更好的方法?
亲切的问候!
最佳答案
为此,需要在 DTCoreText 中实现以下内容:
然后,您可以在委托(delegate)方法中为您自己的 Web View 提供这些内容,从而为文本附件设置自定义 View 。
关于ios - 使用 DTCoreText 嵌入推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29201216/