欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

UILabel可以显示html文本_html/css_WEB-ITnose

程序员文章站 2022-05-23 20:26:36
...
NSString * htmlString = @" Some html string \n This is some text! ”;

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];