iOS UILabel 使用 HTML 字符串样式

效果图

1235875-5e219c266f9827f4.png
样例.png

代码

    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;

猜你喜欢

转载自blog.csdn.net/weixin_34151004/article/details/87112066