18910140161

UILabel可以显示html文本

顺晟科技

2022-09-15 22:30:03

67

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

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

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航