- NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- 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];
只能在iOS7以后运行
本文介绍如何在iOS7及以上版本中,利用Objective-C语言创建一个UILabel,并设置其文本为HTML格式字符串,同时应用不同的字体大小和颜色。
4007

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



