Maison > Article > interface Web > UILabel用原生方法显示HTML文本_html/css_WEB-ITnose
NSString * htmlString = @"今天中午<font size='\"13\"' color='\"red\"'>去哪吃什么</font><font size='\"5\"' color='\"blue\"'>???</font> "; 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];