【发布时间】:2015-10-23 11:22:53
【问题描述】:
我有一个UILabel。我想设置一个字符串,其中还包含一些HTML 标签。字符串是:
NSString *str = @"<p>Hey you. My <b>name </b> is <h1> Joe </h1></p>";
如何在UILabel 上显示此内容
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
mylabel.attributedText=attrStr;
上面的代码没有显示任何内容。
【问题讨论】:
-
stackoverflow.com/questions/4789447/… 。希望对你有所帮助。
-
什么都不显示?
attrStr是零吗?使用error参数怎么样?myLabel是零吗? -
如果
UILabel在您的情况下不起作用,那么您为什么不使用专为它设计的UIWebView?只需禁用滚动即可。
标签: ios objective-c