效果图
代码
NSString * htmlS =[NSString stringWithFormat:@"%@%@%@",@"<center><font style=\"font-size:20px\" color=\"#528852\">如何在 UILabel 中使用 HTML 字符串</font><font style=\"font-size:24px\" color=\"#E46A68\">",@"(UILabel 使用 HTML 样式)",@"</font></center>"];
NSAttributedString *aStr = [[NSAttributedString alloc] initWithData:[htmlS dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
self.label.attributedText = aStr;