NSString * htmlString = @” Some html string \n This is some text! “;
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];
UILabel展示HTML文本
HTML文本展示
最新推荐文章于 2021-06-25 19:11:00 发布
本文介绍了一种使用Objective-C将HTML字符串转换为NSAttributedString的方法,并将其显示在UILabel中。通过设置NSAttributedString的document type为NSHTMLTextDocumentType,可以正确解析HTML内容。
3306

被折叠的 条评论
为什么被折叠?



