第一種:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *strHTML = @"
你好
這是一個例子,請顯示
外加一個tableaaaabbbbcccc
";
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:webView];
[webView loadHTMLString:strHTML baseURL:nil];
}
第二種:
NSString * htmlString = @" Some html string \n This is some text! ";
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];
//正則去除網絡標簽
-(NSString *)getZZwithString:(NSString *)string{
NSRegularExpression *regularExpretion=[NSRegularExpression regularExpressionWithPattern:@"]*>|\n"
options:0
error:nil];
string=[regularExpretion stringByReplacingMatchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, string.length) withTemplate:@""];
return string;
}