在UILable内显示HTML页面内容

注意:这个方法只支持IOS7以上

    NSString * htmlString = @"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];

 

posted @ 2015-09-23 09:09  errorbook  阅读(260)  评论(0)    收藏  举报