UILabel文本为html文本

Tec*_*Bee 3 objective-c ipad ios4

我有一个小问题.

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

就像我正在使用 O bjective C Developer.

怎么做.这在目标C中是否可行?

问候,

san*_*ana 9

对于iOS7,您可以使用:

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;
Run Code Online (Sandbox Code Playgroud)