【问题标题】:HTML String content for UILabel and TextViewUILabel 和 TextView 的 HTML 字符串内容
【发布时间】:2011-01-16 17:27:23
【问题描述】:

我得到了一个包含 html 标记内容的对象,例如:

string = @"<p>This is wonderful</p> <p>Also some &#8216; entidies &#8217; <p>";

所以我想首先将此实体转换为我的标签文本。

第二步是将我的 p 标记转换为换行符。

第三步将我的“img”标签转换为uiimageviews和一些简单的文本格式“b”、“strong”等

你有什么想法可以解决我的问题吗?

【问题讨论】:

    标签: iphone objective-c cocoa-touch iphone-sdk-3.0


    【解决方案1】:

    您应该看看 Three20 项目,它包含一个类 TTStyledTextLabel,它允许您呈现 HtmL-Code 甚至激活链接。

    TTStyledTextLabel  *htmlLabel = [[[TTStyledTextLabel alloc] initWithFrame:self.contentView.bounds] autorelease];
    htmlLabel.userInteractionEnabled = YES;
    [aView addSubview:htmlLabel];
    
    htmlLabel.text = [TTStyledText textFromXHTML:htmlText];
    

    【讨论】:

    • 是否可以只包含这个 TTStyledTextLabel 对象? three20 很大,不是吗?使用 Photoviewer 和其他东西
    • 您可能需要包含的不仅仅是该类,但您很可能能够删除那些您不需要的部分。
    • 我正在使用代码获取标签高度。 . CGSize tempSize = [forStr sizeWithFont:forFont constrainedToSize:CGSizeMake(lblWidth, 20000.0f) lineBreakMode:UILineBreakModeWordWrap]; rowHeight = tempSize.height; 。 . .如果是 html 字符串,我们如何获得高度
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 2017-10-22
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 2011-05-04
    • 2019-11-16
    相关资源
    最近更新 更多