我得到一个 HTML 格式的标题
<p><span style="color: #000000;"><strong>示例</strong></span></p>
我需要在 UILabel 中显示这个 HTML 字符串。颜色代码和字体大小应与 HTML 中的相同。当我将 HTML 字符串转换为 NSString 时,只有文本“Example”出现,而不是颜色。
有什么解决办法吗?
提前谢谢
到目前为止,我正在尝试以下列方式使用 NSAttributedString,但通过这种方式,整个 HTML 正在打印:
UIFont *font = [UIFont systemFontOfSize:14.0];
UIFont *secondFont = [UIFont systemFontOfSize:10.0];
NSMutableDictionary *firstAttributes;
NSMutableDictionary *secondAttributes;
NSDictionary *firstAttributeFont = @{NSFontAttributeName:font};
NSDictionary *secondAttributeFont = @{NSFontAttributeName:secondFont};
[firstAttributes addEntriesFromDictionary:firstAttributeFont];
[secondAttributes addEntriesFromDictionary:secondAttributeFont];
[firstAttributes addEntriesFromDictionary:@{NSForegroundColorAttributeName:[UIColor clearColor]}];
[secondAttributes addEntriesFromDictionary:@{NSForegroundColorAttributeName:[UIColor clearColor]}];
NSString* completeString = [NSString stringWithFormat:@"%@",strTitle];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:completeString];
[attributedString setAttributes:firstAttributes range:[completeString rangeOfString:strTitle]];
// [attributedString setAttributes:secondAttributes range:[completeString rangeOfString:self.secondAttributeText]];
Cell.lbl_Title.attributedText = attributedString;