美文网首页
iOS UILabel 使用 HTML 字符串样式

iOS UILabel 使用 HTML 字符串样式

作者: Yuency | 来源:发表于2019-01-17 11:05 被阅读5次

效果图

样例.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;

相关文章

网友评论

      本文标题:iOS UILabel 使用 HTML 字符串样式

      本文链接:https://www.haomeiwen.com/subject/junbdqtx.html