UILabel文本为html文本 [英] UILabel text as html text

查看:73
本文介绍了UILabel文本为html文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在堆叠一个小问题。

I am stack with a small issue.

我需要使用一个句子,前两个单词加粗,最后两个单词斜体。

I need to use a sentence which will have first two words bold and last two words italic.

就像我正在使用一个O bjective C 开发人员。

like I am using an Objective C Developer.

如何要做到这一点。目标C中是否可以这样做?

How to do that. Is this possible in Objective C?

问候,

推荐答案

iOS7你可以使用这个:

For iOS7 you can use this:

NSString * htmlString = @"<html><body> Some html string </body></html>";
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

UILabel * myLabel = [UILabel alloc] init];
myLabel.attributedText = attrStr;

这篇关于UILabel文本为html文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆