iOS UILabel 使用 HTML 字符串样式

2019-01-17  本文已影响5人  Yuency

效果图

样例.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;
上一篇 下一篇

猜你喜欢

热点阅读