1用uiwebview
NSString *strHTML = @
"<p>你好</p><p> 这是一个例子,请显示</p><p>外加一个table</p><table><tbody><tr class=\"firstRow\"><td valign=\"top\" width=\"261\">aaaa</td><td valign=\"top\" width=\"261\">bbbb</td><td valign=\"top\" width=\"261\">cccc</td></tr></tbody></table><p></p>"
;
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:webView];
[webView loadHTMLString:strHTML baseURL:nil];
2.用uilabel
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[_gameItemDetail.gameDescription dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
UILabel * myLabel = [[UILabel alloc] initWithFrame:CGRectMake(Gap_12*2, 0, SCREEN_WIDTH-Gap_12*4, _tableViewMain.frame.size.height-_heightOfTableViewMainHeader)];
myLabel.attributedText = attrStr;
myLabel.numberOfLines = 0;
myLabel.backgroundColor = [UIColor clearColor];
CGSize sizeLabelText = [NSString sizeLabelWidth:myLabel.frame.size.width attributedText:attrStr];
myLabel.frame = CGRectMake(Gap_12*2, 0, SCREEN_WIDTH-Gap_12*4, sizeLabelText.height);
+ (CGSize)sizeLabelWidth:(CGFloat)width
attributedText:(NSAttributedString *)attributted
{
if(width<=0){
return CGSizeZero;
}
UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 3000)];
lab.attributedText = attributted;
lab.numberOfLines = 0;
CGSize labSize = [lab sizeThatFits:lab.bounds.size];
return labSize;
}