方法一:可以用webview
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
_webView.backgroundColor = [UIColor redColor];
NSString *html_str = [NSString stringWithFormat:@"<div style='color:red'>666666666666666</div> 测试时间 %@",@"新风作浪",@"2013-05-27"];
[self.webView loadHTMLString:html_str baseURL:nil];
[self.view addSubview:self.webView];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 300, 200)];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[@"<font style='font-size:20px;color:red' >666666666666666</font> asdasd " dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
label.attributedText = attributedString;
// label.font = [UIFont systemFontOfSize:18];
[self.view addSubview:label];
本文介绍了两种在iOS应用中展示富文本的方法:一种是利用WebView加载HTML字符串;另一种是通过UILabel结合NSAttributedString来实现。这两种方式均可实现文本的颜色及大小自定义。
7723

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



