iOS UILabel显示HTML文本

2016-05-31  本文已影响3108人  浪漫紫薇星

只能在iOS7以后运行


NSString * htmlString = @" <html><body>Some html string \n<font size=\"13\" color=\"red\">This is some text!</font></body>";  

NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];  

UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];  myLabel.attributedText = attrStr;  [self.view addSubview:myLabel];

上一篇 下一篇

猜你喜欢

热点阅读