1磨淌、UILabel加載標(biāo)簽
NSString *str = @"<p>高于90分的名稱</p>\n<table style=\"border-collapse: collapse; width: 100%; height: 88px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">名稱</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">班級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">年齡</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">成績</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小李</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">76</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小鳳</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">92</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小名</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">91</td>\n</tr>\n</tbody>\n</table>";?
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 100, 300, 400)];
label.attributedText = attrStr;
?label.numberOfLines = 0;?
?[self.view addSubview:label];
? ??????
2魏烫、UITextView加載標(biāo)簽
NSString *str = @"<p>高于90分的名稱</p>\n<table style=\"border-collapse: collapse; width: 100%; height: 88px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">名稱</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">班級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">年齡</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">成績</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小李</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">76</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小鳳</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">92</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小名</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">91</td>\n</tr>\n</tbody>\n</table>";
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 300)];
textView.userInteractionEnabled = NO;
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; ? ?
?textView.attributedText = attrStr;
textView.font = [UIFont systemFontOfSize:14];
?[self.view addSubview:textView];
3沐寺、wkwebView加載標(biāo)簽
NSString *str = @"<p>高于90分的名稱</p>\n<table style=\"border-collapse: collapse; width: 100%; height: 88px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">名稱</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">班級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">年齡</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">成績</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小李</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">76</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小鳳</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">92</td>\n</tr>\n<tr style=\"height: 22px;\">\n<td style=\"width: 22.984015804597703%; height: 22px;\">小名</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">1年級(jí)</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">8歲</td>\n<td style=\"width: 22.984015804597703%; height: 22px;\">91</td>\n</tr>\n</tbody>\n</table>";
WKWebView *webView = [[WKWebView alloc]? initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 300)];
[webView loadHTMLString:str baseURL:nil];
[self.view addSubview:webView];
總結(jié):建議使用wkwebView加載標(biāo)簽使用捌年。