iOS label显示富文本

2020-06-22  本文已影响0人  小码农CC
NSString * htmlString = @" Some html string \nThis 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];

上一篇下一篇

猜你喜欢

热点阅读