我正在寻找一种方法来使用UILabel(或类似的东西)来显示这样的东西:
汤姆:有些消息.
这就像在Facebook应用程序中显示"你在想什么?"的方式.消息.有没有人有任何建议如何处理这个?
我有一个UILabel.我想设置一个字符串,其中还包含一些HTML标签.字符串是:
NSString *str = @"<p>Hey you. My <b>name </b> is <h1> Joe </h1></p>";
Run Code Online (Sandbox Code Playgroud)
我怎么能在上面显示这个 UILabel
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
mylabel.attributedText=attrStr;
Run Code Online (Sandbox Code Playgroud)
上面的代码没有显示任何内容.